SyLon Posted April 8, 2007 Share Posted April 8, 2007 hi This code should return me an array with posts IDs who match the $tag (array), so here what I did: foreach($tag as $k=>$v) { while( $row=mysql_fetch_assoc($query)) { show($row['id'].$v); $post_tags=return_tags_by_id($row['id']); if( in_array($v,$post_tags) && !in_array($row['id'],$matching_posts) ) { $matching_posts[]=$row['id']; } } # while } # foreach After some testing I figured out that the while loop is getting looped only once - only at the first time, while the foreach loop is fine. it seems like $row != mysql_fetch_assoc($query) after the first loop, so I tried to unset($row) at the beginning of each foreach loop but it doesn't work. I'm pretty sure that there is something wrong with my while loop, but what?? Hope you can help, Thanks! Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 well try unset( at the end of the while) and also look at whether or not the query is actually returning anytihng....... good luck Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted April 8, 2007 Share Posted April 8, 2007 mysql_fetch_array() That might fix your problem. Quote Link to comment Share on other sites More sharing options...
SyLon Posted April 8, 2007 Author Share Posted April 8, 2007 Problem solved! I put the query inside the foreach loop, like that: (It's a function and $query is a parameter) foreach($tag as $k=>$v) { $query2=mysql_query($query); while( $row=mysql_fetch_assoc($query2)) { $post_tags=return_tags_by_id($row['id']); if( in_array($v,$post_tags) && !in_array($row['id'],$matching_posts) ) { $matching_posts[]=$row['id']; } } # while } # foreach Thanks for helping guys! ohh, by the way, whats the difference between mysql_fetch_assoc() and mysql_fetch_array() ? Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted April 8, 2007 Share Posted April 8, 2007 mysql_fetch_assoc gets the result row as an associative array, mysql_fetch_array gets it as an associative array, a numerica rray, or both, so basically, with mysql_fetch_assoc, you can only call up the values like this: $row['id']; with mysql_fetch_array, you can call them up like this: $row['id']; or this: $row[1]; calling mysql_fetch_assoc() is the same as this: mysql_fetch_array($result, MYSQL_ASSOC); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.