php For loop not executing correctly

Hello,

I hope you you guys/girls/gentlemen/ladies can help me because i cant figure out what i am doing wrong.

I need to make a forum for a school project in php and the thing i am trying to do is make a php script that shows the main categories and the sub categories, the sub categories work like i want them to, but the main categories stop after 3 for loops.

I include this in my index.php so the background of the body tag (css) should also be taken over but it stops when the table begins (when i take away the code for showing the sub categories, the background displays properly and that is again a mystery for me.)

Here is the database that i am using

[table][tr]
[td]AUTO increment[/td] [td]CAN be NULL[/td][/tr]
[tr]
[td]cat_id[/td] [td]parent_id[/td] [td]cat_name[/td] [td]cat_dis[/td][/tr]
[tr]
[td]1[/td] [td]NULL[/td] [td]test1[/td] [td]test1[/td][/tr]
[tr]
[td]2[/td] [td]NULL[/td] [td]test2[/td] [td]test2[/td][/tr]
[tr]
[td]4[/td] [td]2[/td] [td]hoi2[/td] [td]hoi2[/td][/tr]
[tr]
[td]9[/td] [td]NULL[/td] [td]oke[/td] [td] laatste[/td][/tr][/table]

and here is the piece of code that actually matters (include works)

[php]

<?php include'includes/connect.php'; $table = "category"; $result = mysql_query("select * from ".$table." WHERE parent_id IS NULL") or die ( mysql_error()); // works $count_row = mysql_num_rows($result) or die ( mysql_error()); // it got 4 rows and that was what was in the database at the time so this works echo''; echo''; echo''; echo''; echo''; echo''; // still need h refs if(isset($_SESSION['admin'])){echo'';} if(isset($_SESSION['admin'])){echo'';} if ($count_row > 0) // works also { //doesnt it will only go 3x whatever the row count is for ($i = 0; $i < $count_row ; $i++) { $c1 = mysql_result($result, $i, "cat_id"); $c3 = mysql_result($result, $i, "cat_name"); $c4 = mysql_result($result, $i, "cat_dis"); echo ""; echo ""; echo ""; echo "" ; echo "" ; echo ""; echo ""; $result2 = mysql_query("select * from ".$table." Where parent_id=".$c1."") or die ( mysql_error()); $aantal_rijen2 = mysql_num_rows($result2) or die ( mysql_error()); // works like intended thoh bit weird because the for loop that is above it only goes 3 times for($i2 = 0; $i2 <$aantal_rijen2; $i2++) { $sc1 = mysql_result($result2, $i2, "cat_id"); $sc3 = mysql_result($result2, $i2, "cat_name"); $sc4 = mysql_result($result2, $i2, "cat_dis"); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; }//closing second for loop }// closing first for loop } // closing if aantal rijen >0 echo'

Name

Discription

EditDelete

".$c3."

".$c4."




".$sc3."

".$sc4."




'; ?> [/php]

Any suggestions what i could do differently are also welcome,

Jermey

Well, if you have four rows, you are saying that it is less than four, which is three. Maybe you could use <= or = or ==? (not quite sure which one)

my database atm has 6 NULL parents so main categories but it only shows 3 if i put in <= it has no effect and when i say == it will never display anything for obvious reasons thoh thanks for trying ^^.

Sponsor our Newsletter | Privacy Policy | Terms of Service