Hi there, i have made a website category script, it works, but it seems very messy!!
Can anybody help me tidy it up a bit, and if possible, help me use less database connections!!
Which then leads me onto a second query... what is the maximum number of database queries advisable in one script?
anyway here is my script... rip it guys!!
==========
<?php
// Log into MySQL database
$db = mysql_connect("localhost", "123456", "123456") or die ("Could not connect");
mysql_select_db("ehelper_board") or die ("Could not select db");
$sql = mysql_query("SELECT * FROM forums WHERE parent = '$cat_id'",$db);
if(mysql_num_rows($sql) != 0) {
$query = "SELECT * FROM forums WHERE parent = '$cat_id'";
$sql_result = mysql_query($query, $db) or die ("Couldn't execute query");
while ($row = mysql_fetch_array($sql_result)) {
$sql = mysql_query("SELECT * FROM forums WHERE parent='$row[id]'",$db);
if(mysql_num_rows($sql) < 1) {
$result = mysql_query("SELECT * FROM posts WHERE forumid = '$row[id]' AND replyid = ''", $db);
$var = mysql_num_rows($result);
$type = "Posts";
} else {
$result = mysql_query("SELECT * FROM forums WHERE parent='$row[id]'", $db);
$var = mysql_num_rows($result);
$type = "Forums";
}
?>
<tr><td>
<table border="0" width="510"><tr><td>
<table border="0" cellpadding="1" cellspacing="0" bgcolor="#000000" width="100%"><tr><td>
<table border="0" bgcolor="#d0ccd0" width="100%" onmouseover="this.style.backgroundColor='#5F7797';" onmouseout="this.style.backgroundColor='#d0ccd0'"><tr><td width="100%" class="newshead">
<a href="http://www.ehelper.co.uk/test.php?cat_id=<?php print $row[id]; ?>"><b><font color="#333333"><?php print $row[name]; ?></font></b></a> (<?php print "$var $type"; ?>)
</td></tr></table>
</td></tr></table>
</td></tr>
</table>
</td></tr>
<?php
}
} else {
print "Insert Topic Listing Here!";
}
?>