Page 1 of 1

DATABASE SEARCH

Posted: Fri Feb 26, 2010 10:56 am
by Travelinman612
ok I can connect to my database and pull info from it. I'm trying to search my database (using phpMyAdmin) in DB business, Table rest, and Field Cost. Im looking for "low" in that feild. When i run the code below it gives me this statement.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'Low\' LIMIT 0, 30' at line 1

$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'blabla';
$db_db = 'business';
$db_table = 'rest';

$db_link = mysql_connect($db_host, $db_user, $db_pass)
or die('MySQl Connection Error:'.mysql_error());
mysql_select_db($db_db)
or die('MySQL Error: Cannot select table');
$XX = "No Record Found";
$query = "SELECT * FROM `rest` WHERE `Cost` LIKE \'Low\' LIMIT 0, 30 ";
$result = mysql_query("$query") or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $row[Name] . " " . $row[Style];
echo "<br />";


}

Re: DATABASE SEARCH

Posted: Fri Feb 26, 2010 11:01 am
by AbraCadaver
Why do you have slashes there? \'Low\'

Re: DATABASE SEARCH

Posted: Fri Feb 26, 2010 11:52 am
by Travelinman612
cause i'm looking for "Low" in the field "cost"

Re: DATABASE SEARCH

Posted: Fri Feb 26, 2010 12:00 pm
by Travelinman612
i got that string from phpmyadmin when I did a search on it and hit create php code. it gave me ---- $sql = "SELECT * FROM `rest` WHERE `Cost` LIKE \'low\' LIMIT 0, 30 ";

Re: DATABASE SEARCH

Posted: Fri Feb 26, 2010 12:45 pm
by Kurby
Travelinman612 wrote:i got that string from phpmyadmin when I did a search on it and hit create php code. it gave me ---- $sql = "SELECT * FROM `rest` WHERE `Cost` LIKE \'low\' LIMIT 0, 30 ";
Not sure why it put the \ in there, thats what is breaking it. Also, if your not using wildcard of any kind in your search statement than don't use LIKE. Just use

Code: Select all

SELECT * FROM `rest` WHERE `Cost` = 'low' LIMIT 0, 30

Re: DATABASE SEARCH

Posted: Fri Feb 26, 2010 12:54 pm
by Travelinman612
Yeah it worked!!!!. Guess i was over complicating things!