I am staring into this one for hours. I am not able to find the mistake. Can anyone tell me what wrong did I do? Or is there a better way to compare?
$res1=mysql_query(**query for table1**);
$n1=mysql_num_rows($res1);
$res2=mysql_query(**query for table 2**);
$n2=mysql_num_rows($res2);
for($i=0;$i<$n1;$i++)
{
$r1=mysql_fetch_row($res1);
for($j=0;$j<$n2;$j++)
{
$r2=mysql_fetch_row($res2);
if($r1[0]==$r2[0])
{
echo $r1[0]."<br>";
}
}
}
table 1 contains these elements: 1,2,3,16,18,19,20,21,22,24,23
table 2 contains : 23,21
However, the program returns zero matches. Why?
So what is happening here is
The result two elements are getting exhausted in the first iteration.
from the example data you have posted, here is the looping:
when r1 is 1,
r2 is 23,21
when r1 is 2,
r2 is exhausted.
To reset result two again, you will have to do
mysql_data_seek($res2,0);
each time
i.e your for loop will look like this