I have a table up_vadba in wich I have some records that needs to be printed out. I created three nested while loops (see below), which returns main category, subcategory and subcategory results.
Everything is OK, except the last subcategory results might output too many results if previous subcategory results had more results than the last - I hope you understand what I'm explaining? For the first main category I have two subcategories and in each subcategories are two or more subcategory results. This code outputs as many subcategory results as they are in previous subcategory, instead of the right number of results.
I'm bumping in the wall with my head for a few days now to solve this problem and it seems I just can't figure it out. I also used the mysqli_fetch_array function, used counter and nothing helped.
Could any of you took a look what is wrong with the code? Thanks guys, would save me a wall :D
$sql="SELECT * FROM up_vadba WHERE upid='$usid' GROUP BY vadba"; //it gets main category
$vadbe=mysqli_query($cxn,$sql) or die ("Nisem uspel izvesti poizvedbe vadb");
while($vadba=mysqli_fetch_assoc($vadbe)) //as long as there is main category
{
echo "Vadba ".$vadba['vadba']."<br>";
$sqlvaje="SELECT * FROM up_vadba WHERE upid='$usid' GROUP BY imeVaje"; //it gets subcategory
$vaje=mysqli_query($cxn,$sqlvaje) or die ("Nisem uspel izvesti poizvedb vaj");
while($vaja=mysqli_fetch_assoc($vaje)) //as long as there is subcategory
{
echo $vaja['imeVaje']."<br>";
$sqlserije="SELECT * FROM up_vadba WHERE upid='$usid' GROUP BY serija"; //it gets subcategory results
$serije=mysqli_query($cxn,$sqlserije) or die ("Nisem uspel izvesti poizvedb serij");
while($serija=mysqli_fetch_assoc($serije)) //as long as there are subcategory results
{
echo "serija".$serija['serija']." ".$serija['ponovitve']." ponovitev<br>";
}
}
}
I got this output:
Vadba 1
- počep
serija 1
serija 2
serija 3
- izpadni korak
serija 1
serija 2
serija 3
Instead of:
Vadba 1
- počep
serija 1
serija 2
serija 3
- izpadni korak
serija 1
serija 2
echo "serija".$serija['serija']." ".$serija['ponovitve']." ponovitev<br>";this is not compatible with the out put you provided! where isponovitevword in the output?