Here's my situation...I've been learning to write PHP for awhile and have been trying to rewrite my web site from plain old static pages to PHP versions. I've been learning based on what I want to do, put my links and articles in databases and allow comments and ratings.
I have a test page here:
http://www.smorgasbord.net/ani-gifs/index6.shtml
I've managed to write the PHP code to do just about everything I wanted, but it takes about 3+ seconds for the page to start to load (and it didn't when it was a static page). I know that this is because of my badly formed PHP no doubt. The routines do what I want, but there HAS to be a much more efficient way to get it done.
I'm going to post the code (stipped of font tags and error catching statements). Please advise the easiest way to streamline this code (and or SQL statements) in the best interest of the server processing time (any help would be great!):
<?php
//Start of routine for animation links
$usr = "user";
$pwd = "pw";
$db = "db";
$host = "host";
$cid = mysql_connect($host,$usr,$pwd);
?>
<?php
//We want the Animated Gif category
$category = "1";
$SQL = " SELECT * FROM links_temp";
$SQL = $SQL . " WHERE category = '$category'";
$retid = mysql_db_query($db, $SQL, $cid);
//Throw the links in an array - html table loop
print ("<center><table cellpadding=2 cellspacing=0 width=100% border=1>\n");
while ($row = mysql_fetch_array($retid)) {
$siteurl = $row["siteurl"];
$sitename = $row["sitename"];
$description = $row["description"];
//cocatenate together anigif with each item id for unique rating value
$id = "anigif";
$id = $id . $row["id"];
print ("<tr><td width=100% valign=top>");
//Lets start the form here for the voting to elimate a line break later
print ("<form method=\"POST\" action=\"/test/rating4.php\" onsubmit=\"return genwin()\" target=\"newwin\">\n");
print ("<A HREF='$siteurl' target=_blank>$sitename</A>");
//While in the while loop lets start another db connection to get item ratings
$usr3 = "user";
$pwd3 = "pw";
$db3 = "db";
$host3 = "host";
$cid3 = mysql_connect($host3,$usr3,$pwd3);
$SQL3 = " SELECT * FROM ratings_temp WHERE item = \"$id\"";
$result3 = mysql_db_query($db3,"$SQL3",$cid3);
$num_rows = mysql_num_rows( $result3 );
if ($num_rows==0) { echo ("No Votes yet"); }
else {
print " $num_rows Votes, ";
$SQL4 = "SELECT AVG(value) AS avgRating FROM ratings_temp WHERE item = \"$id\"";
$result4 = mysql_db_query($db3,"$SQL4",$cid3);
print "Rating: " . mysql_result($result4,0) . "<br>";
}
mysql_close($cid3);
//end of the db connection for ratings
print ("$description<br>\n");
print ("Vote for this Site!\n");
print (" <select name=\"rating\" size=\"1\">\n");
print (" <option value=\"5\" selected>5 - Superb\n");
print (" <option value=\"4\">4 - Tasty\n");
print (" <option value=\"3\">3 - Average\n");
print (" <option value=\"2\">2 - Bland\n");
print (" <option value=\"1\">1 - Rotten\n");
print (" </select>\n");
print (" <input type=\"hidden\" name=\"item_id\" value=\"$id\">\n");
print (" <input type=\"submit\" value=\"Vote\">\n");
print ("</form>\n");
print ("</td></tr>\n");
}
//end of the array subroutine making table rows
print("</table></center>");
//end of the table after the array ends
?>