Hey, ich habe einen PHP Code geschrieben, der alle Teiler einer Zahl, die man eingibt anzeigen soll.
Leider lädt die Seite ewig, wenn ich den Teiler berechnen will.
Hier erstmal der Code:
PHP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Teilerliste</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="phpkid.css">
</head>
<body>
<h2>Teilerliste</h2><br />
<p>
<form action="teiler.php" method="POST">
Zahl: <input type="Text" name="zahl"><br />
<input type="submit" value="Teiler Berechnen">
<br />
<br />
</form>
<?php
if(isset($_POST['zahl'])) {
$teiler = 2;
$zahl = $_POST['zahl'];
while($teiler < $zahl) {
$r = round($zahl / $teiler);
if($r == 0) {
echo "$teiler <br />\n";
$teiler = $teiler + 1;
}
}
}
?>
</body>
</html>
Alles anzeigen
Also mit Teiler meine ich, die Zahlen durch die eine Zahl ohne Rest geteilt werden kann. ein Beispiel:
Zahl: 12
Ergebnisse:
2
3
4
6
In dem Code verhindere ich, dass 1 angezeigt wird, da jede Zahl durch 1 teilbar ist.
Die Fehlermeldung nach einiger Zeit:
Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\Php\Teilerliste\teiler.php on line 24