christo16 Posted August 9, 2007 Share Posted August 9, 2007 Hello all, I would like to be able to match values from my mysql table to an array. For example: $result = mysql_query('SELECT * FROM db'); while ($row = mysql_fetch_array($result)) { if ($array == $row[id]){ echo "We found your value"} } I realize this isn't a functional example, but basically I would like to match the id value with the same value in the array and if it doesn't exist go to the next row of the mysql. I've tried a few things such as array_filter, with no success. It seems like theres an easy way to do this that I don't know of. Thank you for any help! Link to comment https://forums.phpfreaks.com/topic/64032-solved-find-mysql-row-in-an-array/ Share on other sites More sharing options...
JJohnsenDK Posted August 9, 2007 Share Posted August 9, 2007 $result = mysql_query('SELECT * FROM db WHERE id = '$id''); $numrows = mysql_fetch_rows($result); if($numrows != 0){ echo "We found your id!"; } Link to comment https://forums.phpfreaks.com/topic/64032-solved-find-mysql-row-in-an-array/#findComment-319162 Share on other sites More sharing options...
christo16 Posted August 9, 2007 Author Share Posted August 9, 2007 Hello JJohnsenDK, Thank you for the reply, I don't see how this would work with my array. For each row pulled from the DB, i would like it to search the array for that particular row. Any input is appreciated! Link to comment https://forums.phpfreaks.com/topic/64032-solved-find-mysql-row-in-an-array/#findComment-319163 Share on other sites More sharing options...
rajmohan Posted August 9, 2007 Share Posted August 9, 2007 actually what is $array here Link to comment https://forums.phpfreaks.com/topic/64032-solved-find-mysql-row-in-an-array/#findComment-319165 Share on other sites More sharing options...
christo16 Posted August 9, 2007 Author Share Posted August 9, 2007 You know what guys, I actually solved it. I really should have played around with it more before posting here. The array is just a bunch of integers. What I did: $result = mysql_query('SELECT * FROM db'); while ($row = mysql_fetch_array($result)) { if (in_array($row[id], $array)) { echo $row[id]; } } Link to comment https://forums.phpfreaks.com/topic/64032-solved-find-mysql-row-in-an-array/#findComment-319170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.