Weet iemand hoe ik een slecht script moet optimizen?
Geplaatst: 10 dec 2004, 08:08
Code: Selecteer alles
<?php
set_time_limit(45);
$dblinkblabla = mysql_connect('localhost', 'gebruiker', 'password');
mysql_select_db('wordpress', $dblinkblabla);
$mode = $_GET['mode'];
include "./classes/Validator.php";
$valid = new Validator;
switch ($mode) {
case 'next':
$uid = $_GET['id'];
$ucat = $_GET['cat'];
$i = 0;
$catfound = 0;
$sqltemp = "SELECT COUNT(*) AS tel FROM webring_sites";
$rowcount = mysql_fetch_assoc(mysql_query($sqltemp));
$rowcount = $rowcount['tel'];
while ($catfound != 1) {
$i++;
$dingesidofzo = $i + $uid;
$sql = "SELECT * FROM webring_sites WHERE catid=$ucat AND id=$dingesidofzo";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result) == 0) {
$catfound = 0;
} else {
$catfound = 1;
}
if ($i > $rowcount) {
exit;
}
}
$url = $row['url'];
header('Location: ' . $url);
break;
case 'vorige':
$uid = $_GET['id'];
$ucat = $_GET['cat'];
$i = 0;
$catfound = 0;
$sqltemp = "SELECT COUNT(*) AS tel FROM webring_sites";
$rowcount = mysql_fetch_assoc(mysql_query($sqltemp));
$rowcount = $rowcount['tel'];
while ($catfound != 1) {
$i++;
$dingesidofzo = $i - $uid;
$sql = "SELECT * FROM webring_sites WHERE catid=$ucat AND id=$dingesidofzo";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if (mysql_num_rows($result) == 0) {
$catfound = 0;
} else {
$catfound = 1;
}
if ($i > $rowcount) {
exit;
}
}
$url = $row['url'];
header('Location: ' . $url);
break;
case 'lijst':
echo "<HTML><HEAD><Title>WebRing</Title></head>";
echo "<body bgcolor=\"#EDECE2\">";
$sql2 = "SELECT * FROM webring_sites";
$result = mysql_query($sql2);
echo "<table width=\"100%\">";
echo "<tr><td width=\"12%\">ID</td><td width=\"88%\">Link</td></tr>";
if (mysql_num_rows($result) == 0) {
echo "<tr><td colspan=\"2\">:'( wil niet :'('</td></tr>";
} while ($row = mysql_fetch_assoc($result)) {
$wid = $row["id"];
$wurl = $row["url"];
$wttl = $row["titel"];
echo "<tr><td>$wid</td><td><a href=\"$wurl\">$wttl</a></td></tr>";
}
echo "</table>";
echo "</body></html>";
break;
case 'register1':
echo "<HTML><HEAD><Title>WebRing</Title></head>";
echo "<body bgcolor=\"#EDECE2\">";
include "./classes/phpForm.php";
$form = new phpForm;
$form->addInputText("title", "Titel van je site");
$form->addInputText("url", "De URL van je site");
$form->outputForm("?mode=register2");
echo "</body></html>";
break;
case 'register2':
$titel = $_POST['title'];
$url = $_POST['url'];
$valid->validateTextOnly($titel, "Titel");
$valid->validateGeneral($url, "URL");
if ($valid->foundErrors()) {
echo "<b>Er was een probleem met: <br />".$valid->listErrors("<br />");
} else {
$sql = "INSERT INTO webring_sites (id, catid, url, titel)"
. " VALUES ('', 1, '$url', '$titel')";
mysql_query($sql) or die(mysql_error() . "<br />" . $sql);
$id = mysql_insert_id();
echo "Done :)";
echo "Je code is: ";
?>
<pre>
<script src="http://btweb.no-ip.biz:30000/webring.php?mode=code&id=<?php echo $id;
?>" type="text/javascript"><br />/* Webring Code */<br /></script>
</pre>
<?php
}
break;
case 'code':
$id = $_GET['id'];
header("Content-type: text/javascript");
echo "document.write(\"<center><table>\");";
echo "document.write(\"<tr><td colspan=\\\"4\\\">\");";
echo "document.write(\"<h1>WebRing</h1></td></tr><tr><td>\");";
echo "document.write(\"<a href=\\\"http://btweb.no-ip.biz:30000/webring.php?mode=next&id=$id&cat=1\\\">Volgende</a>\");";
echo "document.write(\"</td><td><a href=\\\"http://btweb.no-ip.biz:30000/webring.php?mode=vorige&id=$id&cat=1\\\">Vorige</a>\");";
echo "document.write(\"</td><td><a href=\\\"http://btweb.no-ip.biz:30000/webring.php?mode=lijst\\\">Lijst</a></td>\");";
echo "document.write(\"</td><td><a href=\\\"http://btweb.no-ip.biz:30000/webring.php?mode=register1\\\">Registreer</a></td></tr></table></center>\");";
break;
default:
echo "<h1>WebRing</h1>";
echo "<a href=\"?mode=register1\">Registreer</a>";
}
?>

Maar weet iemand hoe ik het moet optimaliseren? (en dan vooral de next en vorige)