Jump to content

[SOLVED] Possible Syntax Error in Query


Bopo

Recommended Posts

Hey

 

I have wrote this query for php, however I am not sure if its valid to use so many clauses, or possibly I might have a syntax error, I have tried a few different things such as double quotes around the varible, and percentage signs but no luck so far, help appreciated.

 

$cartype = "BMW 1 Series";
$result = mysql_query("SELECT * FROM cardata WHERE model LIKE = '$cartype' LIMIT 1");

Link to comment
https://forums.phpfreaks.com/topic/131216-solved-possible-syntax-error-in-query/
Share on other sites

depends...do you want it to be an exact match? so the 'model' field is equal to the string in $cartype? if so, use:

$cartype = "BMW 1 Series";
$result = mysql_query("SELECT * FROM cardata WHERE model = '$cartype' LIMIT 1");

 

LIKE should be used when you want to (for instance) find all the models with BMW in the name:

$cartype = "BMW";
$result = mysql_query("SELECT * FROM cardata WHERE model LIKE '%$cartype%'");

Hi and thanks for you help

 

The Model column doesn't have 'BMW 1 Series' on its own anywhere, and this applies to all the other vechiles within it, for example

 

BMW 1 Series 2dr coupe

BMW 1 Series 2dr convertible

BMW 1 Series 3dr hatchback

BMW 1 Series 5dr hatchback

 

 

So I would like the query to retrive the first record it finds with the words 'BMW 1 Series' within the Model column, I know this might seen vague, but this would be suitable for what I am doing.

 

Cheers

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.