This is how I rewrote your script, imagining there being 22 missing calls to the db, but you should get the idea.
I have not tested this code, and there may well be some syntax errors as I just typed it out.
PHP Code:
<?php
// Set the variables for the database access, you only need to do this once
// if the same db holds all the info your script needs
// you just change the SQL query
$Host = "";
$User = "";
$Password = "";
$DBName = "";
$Link = mysql_connect ($Host, $User, $Password);
// give your query a name which represents what it is doing
// I am guessing this is getting categories?
$catsQuery = "SELECT id,name,ogtableid,catid FROM category WHERE ogtableid = '1' ORDER by name";
// give your results set a name which then is representative of
// what it contains, in this case I am guessing a load of categories
$categories = mysql_db_query ($DBName, $catsQuery, $Link);
// Fetch the results from the database.
while($cat = mysql_fetch_array($categories)){
$catid = $cat['catid']; // NB you quote the key not the entire array ...
print ("· <a href=\"http://www.vancouverprofile.com/business/agricultural/category.php/catid/" . $cat['catid] ."\" class=\"link\">" . $cat['name'] . "</a>");
?>
( <?php
// again make the variable names be descriptive of their contents
$profileCountQuery = "SELECT count(id) FROM profiles WHERE productcodes1='$catid' OR productcodes2='$catid' OR productcodes3='$catid' OR productcodes4='$catid' OR productcodes5='$catid' OR productcodes6='$catid' OR productcodes7='$catid' OR productcodes8='$catid' OR productcodes9='$catid' OR productcodes10='$catid' OR productcodes11='$catid' OR productcodes12='$catid' OR productcodes13='$catid' OR productcodes14='$catid' OR productcodes15='$catid'";
// you already connected to the dbase so just re-use the connection you made at the start of the script
$profileCounts = mysql_db_query ($DBName, $Query, $Link);
$counts = mysql_result($profileCounts,0,"count(id)");
// Fetch the results from the database.
echo $counts;
?> )
<?
}
?>
note:
You only need to connect to the db once
You do not need to close the db connection, this happens when the script dies
$Query23 is a meaningless variable name, it does not help you understand what it contains, you may want to reuse that variable further down the script
To access an array variable you do
echo $row['id'];
NOT
echo "$row[id]";
To access an array variable inside a string you concatenate the string using the dot character.
echo "Your id is " . $row['id'] . ", thank you.<br />";
Bookmarks