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? Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/ Share on other sites More sharing options...
freelance84 Posted October 18, 2010 Share Posted October 18, 2010 is the query correct? - mysql_error() - Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123468 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? Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123472 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>"; Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123476 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()); Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123477 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>"; Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123478 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! Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123481 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. Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123483 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? Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123484 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. Link to comment https://forums.phpfreaks.com/topic/216171-getting-errors-that-no-array-exists/#findComment-1123496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.