tyler_durden Posted October 18, 2010 Share Posted October 18, 2010 $result = mysql_query("SELECT field_item_id_value FROM `content_type_ads`"); while($row = mysql_fetch_array($result)){ echo $row['field_item_id_value']; echo "<br />"; echo $result; } I am trying to use an "array diff()" argument and I am getting errors with it stating the above is not an array. I have used $row and $result, and neither work. Is this not dumping into an array properly? Quote Link to comment Share on other sites More sharing options...
freelance84 Posted October 18, 2010 Share Posted October 18, 2010 is the query correct? - mysql_error() - Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 18, 2010 Share Posted October 18, 2010 I don't see any array_diff() in that code. $row should be an array (although it is an array with just one element based on your query), but $row['field_item_id_value'] would not. Are you sure the query is executing without errors? Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 18, 2010 Share Posted October 18, 2010 try this and see what you get $result = mysql_query("SELECT field_item_id_value FROM content_type_ads"); $i=0; while($row = mysql_fetch_array($result)){ $my_array[$i] = $row['field_item_id_value']; $i ++; } echo "<PRE>"; print_r($my_array); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2010 Share Posted October 18, 2010 i agree with the previous posters. if your query is failing and you don't know, you'll be hacking in circles until you find out. $result = mysql_query("SELECT field_item_id_value FROM content_type_ads") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 18, 2010 Share Posted October 18, 2010 try this and see what you get $result = mysql_query("SELECT field_item_id_value FROM content_type_ads"); $i=0; while($row = mysql_fetch_array($result)){ $my_array[$i] = $row['field_item_id_value']; $i ++; } echo "<PRE>"; print_r($my_array); echo "</pre>"; The $i variable is unnecessay in that code. Try this: $query = "SELECT field_item_id_value FROM content_type_ads"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $my_array[] = $row['field_item_id_value']; } echo "<pre>"; print_r($my_array); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
tyler_durden Posted October 18, 2010 Author Share Posted October 18, 2010 litebearer's code worked, along with the diff() code I had in another part of the page. Thanks! Quote Link to comment Share on other sites More sharing options...
tyler_durden Posted October 18, 2010 Author Share Posted October 18, 2010 Changed to mjdamato's and it works also, thanks again. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 18, 2010 Share Posted October 18, 2010 Changed to mjdamato's and it works also, thanks again. So, what was the problem? Quote Link to comment Share on other sites More sharing options...
tyler_durden Posted October 18, 2010 Author Share Posted October 18, 2010 With the added "$my_array[$i] = $row['field_item_id_value'];", it looks like I was not putting it into any array but only looping and echoing it out. So it lloked correct on the screen, but I couldn't use it in any query because it was no in an array. 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.