php mysql_fetch_array() not working as expected -
$result = mysql_query($strsql); foreach($bestmatch_array $restaurant) { while($row = mysql_fetch_array($result)) { if($restaurant == $row[0]) { $value = $row[1]; } } }
what trying sort result of array formed query according values stored in $bestmatch array.
i don't know doing wrong 4th line seems run once. please guys. thanx in advance.
php mysql_fetch_array() not working expected
your expectation not right.
foreach($bestmatch_array $restaurant) { // loop run first iteration of foreach. while($row = mysql_fetch_array($result)) { } // has been fetched now. }
that logically incorrect sequence.
you expect inner loop called on , on again many times have outer loop run record fetch not work that. outer loop's first run rows in $result fetched , since not reset counter after while loop means after first run there no more rows next run.
solution? fetch row mysql first use simple in_array
call check whether restaurant there in array.
$result = mysql_query($strsql); while($row = mysql_fetch_array($result)) { $name=$row[0]; if(in_array($name,$bestmatch_array)) $value=$name; }
Comments
Post a Comment