slashpine Posted December 3, 2008 Share Posted December 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/ Share on other sites More sharing options...
revraz Posted December 3, 2008 Share Posted December 3, 2008 Use mysql_error() after your query to see why it's failing Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/#findComment-705166 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 $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. Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/#findComment-705167 Share on other sites More sharing options...
slashpine Posted December 3, 2008 Author Share Posted December 3, 2008 thanks for the quick replies... This is weird...I get the error that: Table 'mesg.bizlist'doesn't exist but it does... and where did the "mesg." part come from? Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/#findComment-705173 Share on other sites More sharing options...
revraz Posted December 3, 2008 Share Posted December 3, 2008 Paste your table structure. Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/#findComment-705212 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 mesg is the name of your database. Make sure you are using the correct database for this and that the table name is correct.. Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/#findComment-705218 Share on other sites More sharing options...
slashpine Posted December 3, 2008 Author Share Posted December 3, 2008 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...??? Quote Link to comment https://forums.phpfreaks.com/topic/135385-problem-changing-sql-query-in-php-script/#findComment-705244 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.