Jump to content

problem changing sql query in php script


slashpine

Recommended Posts

I am not a php coder (just a hack) so I hope someone can see fit to offer some suggestions on how I can get this to work for me...

 

The script queries a database for business listings in a particular county...the user clicks a category and the listings are displayed (see array)

 

I would like to diversify this script to query the database to return the listings of a selected category BUT...only for a particular city...

 

Here is the existing code that works:

$results = mysql_query("SELECT  `name` , `address` , `city` , `phone` , `www` ,`id` FROM `bizlist` WHERE 1 AND `category` LIKE '%$query%'  ORDER BY name ASC LIMIT $page, $limit");
while ($data = mysql_fetch_array($results))

 

here is what I am trying to get working...this query works in phpmyadmin but not in the script (see error below)


$results = mysql_query("SELECT  `name` , `address` , `city` , `phone` , `www` ,`id` FROM `bizlist` WHERE `city` = 'Newark' AND `category` LIKE '%$query%'  ORDER BY name ASC LIMIT $page, $limit");
while ($data = mysql_fetch_array($results))

 

"mysql_fetch_array(): supplied argument is not a valid MySQL result resource"

 

any ideas ?

 

TIA

 

Link to comment
Share on other sites


$results = mysql_query("SELECT  `name` , `address` , `city` , `phone` , `www` ,`id` FROM `bizlist` WHERE `city` = 'Newark' AND `category` LIKE '%$query%'  ORDER BY name ASC LIMIT $page, $limit") or die(mysql_error());
while ($data = mysql_fetch_array($results))

 

Add that and see what the error is in the sql.

Link to comment
Share on other sites

the problem was it should have been $numresults and not $results

 

sorry I missed this and did not post the reference

 

but I am confused about the mesg database...I do have a db named "mesg" BUT it is NOT the datbase that the script connects to...this is really confusing...???

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.