I am very new to php, and need your help
I have 2 tables, one for main categories, and the other for sub categories
I am listing the main categories within 3 columns per each row like this:
Main Category 1 Main Category 2 Main Category 3
Main Category 4 Main Category 5 Main Category 6
Table Name: maincategories
Fields: id, main
And at the same time counting sub categories that belong to each main category
Table Name: subcategories
Fields: id, main_id, sub
I keep seeing this error:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 27 on MySQL result index 10
I can see the main category name, but can never see the sub category counts
this is the code:
Code: Select all
<?php
include "config.php";
$result = mysql_query("SELECT * FROM maincategories ORDER BY main") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$myvar = $row[id];
$query = "SELECT main_id, COUNT(sub) FROM subcategories WHERE main_id = '$myvar' GROUP BY main_id";
$display_columns = 3;
$count = mysql_numrows($result);
$padding = ($display_columns-1)-(($count-1)%$display_columns);
print "<table border='0' width='100%' cellspacing='0' cellpadding='0'>\n";
for($i=0; $i<$count; $i++){
if($i%$display_columns == 0)
print "<tr>\n";
print "<td width=\"33%\">\n";
$result2 = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result2)){
echo '<IMG SRC="images/icon.jpg" WIDTH="44" HEIGHT="44" border="0">
<a href="category.php?category=' . mysql_result($result,$i,$main) . '"><strong>
' . mysql_result($result,$i,"main") . '' . mysql_result($result2,$myvar) . 'Sub Category
</strong></a>';
}
print "<p> </p>\n";
print "</td>\n";
if($i%$display_columns == $display_columns-1)
print "</tr>\n";
}
if($padding!=0){
for($i=0;$i<$padding;$i++)
print "<td width=\"33%\"></td>\n";
print "</tr>\n";
}
print "</table>\n";
}
mysql_close($link);
?>Thank you in advance