i have this part of a code and i cant understund why the second loop inside the first does not work. I query two tables and i placed an echo inside the second table to see if it echo’s but it does not either . thanx in advance
while($row = mysql_fetch_array($result))
{
echo "<li class=\"s01\"><a class=\"s03\" href=" . $row['link'] . "><span>". $row['onomaselidas'] ."</span></a>\n";
echo "<ul class=\"pn2\">\n";
$idd[]=$row['idwebsiteprimary'];
while($row2 = mysql_fetch_array($result2))
{
echo "test";
if($idd[$url]==$row2['idwebsite'])
{
echo "<li class=\"s01\"><a href=\"a\"><span>". $row2['name'] ."</span></a></li>\n";
}
}
echo "</ul>\n";
}
After the first iteration of the first loop, the internal pointer of the second result set is at the end, so the second loop will not execute, because
mysql_fetch_array()will returnfalseimmediately. If you want to it exactly as above – the second result set is not dependant on the first – you will need to do this:Alternatively, you can reset the internal pointer of
$result2on each iteration of the first loop by callingmysql_data_seek($result2, 0);like this: