Jump to content

Getting errors that no array exists ?


tyler_durden

Recommended Posts

$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

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>";

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>";

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.