Jump to content

Warning: array_shift() [function.array-shift]: The argument should be an array i


risestar

Recommended Posts

I am having some problems getting a query correct. Basically I have two tables, one with listings and another with categories. In the listings table I have a column called shortdescription.

 

I am trying to pull the shortdescription from the listings table with the query

 

$shortdesc = array_shift(mysql_fetch_row(mysql_query("select shortdescription from links where category = '".$scat->id."' ")));

 

The shortdecription display properly on the pages display the listings, however I am getting the following error on any pages that only display the parent categories

 

 

Warning: array_shift() [function.array-shift]: The argument should be an array in /home/...path/file.php on line 1462

 

The listings id numbers begin at 75+ because the initial parent category id ends at 74. The query seems to be searching for listing ids below 75 and spitting out an error because it is not finding them.

 

Any ideas on how to eliminate this error and/or stop the query from looking for non-existant data?

Link to comment
Share on other sites

Chaining your function calls together like this is a terrible idea. You have absolutely no error handling in place. One of these method calls could (and has) failed but because they all feed into each other like that you have mo way of checking to find out where the error is.

Link to comment
Share on other sites

As recommended on another forums i tried

 

$sql="select shortdescription from links where category = '".$scat->id."' ";

$result=mysql_query($sql) or die(mysql_error());

$row=mysql_fetch_row($result);

$shortdesc = array_shift($row);

 

but it did not make a difference, same error.

Link to comment
Share on other sites

perhaps your query is not returning any rows in its results set. Add a little more error handling.

 

$sql="select shortdescription from links where category = '".$scat->id."'";
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_row($result);
if(!$row)
{
   echo "no rows grabbed";
}
else
{
   $shortdesc = array_shift($row);
}

Link to comment
Share on other sites

http://www.quadcorral.com/placestoride/directory/United_States/United_States.html  is the page

 

Yes, that is the problem, it is grabbing rows for the individual listings, but the main categories, which have no shortdescriptions, of course have no rows to grab.  So I need to either refine a way to grab only rows from the individual listings or a way to filter out the main and subcategories

 

As you can see, its looking for rows in the main categories, which there are none, but if you click on a category, you will see the individual listings which have rows

Link to comment
Share on other sites

There are two possible problems:

1)  There SHOULD be a row, and there isn't one:  Fix your query.

2)  There shouldn't be a row.  Your code expects there to be a row all the time, but now there's a situation in which not having a row is legitimate.  Fix your code the way you've already been shown.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.