Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using COALESCE function

Status
Not open for further replies.

iffoiffy

Programmer
Feb 24, 2005
67
CA
Hi,

Do you see any thing wrong with the following.
I was suggested to use the follwing SQL.
No matter what values I have for the variables all the records get picked.. instead of picking no record

****************
$search_image= "junk";
$search_brand="junk";

$result1= mysql_query("SELECT product_id, model,retail_price,product_image_small FROM products WHERE brand = COALESCE(@search_brand, brand) AND product_image_small = COALESCE(@search_image, product_image_small) " )
or die("Couldn't execute query: " . mysql_error());

****************************
I tried following too, that produced the same results

$search_image= "junk";
$search_brand="junk";

$result1= mysql_query("SELECT product_id, model,retail_price,product_image_small FROM products WHERE brand = COALESCE(@'$search_brand', brand) AND product_image_small = COALESCE(@'$search_image', product_image_small) " )
or die("Couldn't execute query: " . mysql_error());

Thanks
 
Store SQL to a variable and print out the variable. Then inspect if it looks the way you want it to look and copy it to your favorite SQL editor and check if it works. Continue from there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top