$count =0;
$result1 = mysql_query("SELECT fwid FROM sbsw WHERE fword = '".$searchText."'");
while ($result2= mysql_fetch_array($result1))
{
$result3 = mysql_query("SELECT fsyn FROM wrsyn WHERE fwid = '".$result2[$count]."'");
$result4= mysql_fetch_array($result3);
print $result4[$count].'<br>';
$count++;
}
mysql_free_result($result1);
mysql_free_result($result3);
$count =0; $result1 = mysql_query(SELECT fwid FROM sbsw WHERE fword = ‘.$searchText.’); while ($result2=
Share
Let’s have a look at how mysql_fetch_array works – for example if you have table structure like
When you execute a query
SELECT * FROM tableand then loop$result = mysql_fetch_array($query),$resultwill always be an array(4) containingTherefore, when you execute the query
$result3 = mysql_query("SELECT fsyn FROM wrsyn WHERE fwid = '".$result2[$count]."'");, in the first iteration,$countwill be0which is the key for the result returned by the previous query, however in any further iteration it will increase and that will lead to an undefined key. This means that you have to stop using the variable$countand just use$result2[0]instead.Also, way better approach to this would be using MySQL
JOIN, in your example it would beSELECT w.fsyn FROM sbsw s JOIN wrsyn w ON s.fwid = w.fwid WHERE s.fword = "'.$searchText.'";