aruns Posted February 14, 2009 Share Posted February 14, 2009 mysql_query("select a.products_name, a.products_id, b.products_id, b.products_price from products_description a, products b where a.products_id = b.products_id and b.products_price = '$price' and a.products_name = '$name'")or die("Error : " . mysql_error()); anybody help me whats the problem in my query...? Link to comment https://forums.phpfreaks.com/topic/145181-problem-in-select-query/ Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 Try this: SELECT a.products_name, a.products_id, b.products_id, b.products_price FROM products_description a INNER JOIN products b USING (products_id) WHERE b.products_price = '$price' AND a.products_name = '$name'; You may want to take a look at this tutorial as well: http://www.phpfreaks.com/tutorial/data-joins-unions You might want to explain how it doesn't work though. Link to comment https://forums.phpfreaks.com/topic/145181-problem-in-select-query/#findComment-762002 Share on other sites More sharing options...
bubbasheeko Posted February 14, 2009 Share Posted February 14, 2009 In addition, I always make it a practice to use quotes in my queries. mysql_query("SELECT `a`.`products_name`, `a.`products_id`, `b`.`products_id`, `b`.`products_price` FROM `a`, `b` WHERE `a`.`products_id` = `b`.`products_id` && `b`.`products_price` = '" . $price . "' && `a`.`products_name` = '" . $name . "'")or die("Error : " . mysql_error()); Your tables appeared wrong according to your select string a.products_name = table name is 'a' and the field name is 'products_name'. Replace the 'a' and 'b' table names with the table names you have. As Daniel said, let us know the error message you are receiving...it helps us to help you solve your issue. Link to comment https://forums.phpfreaks.com/topic/145181-problem-in-select-query/#findComment-762176 Share on other sites More sharing options...
corbin Posted February 14, 2009 Share Posted February 14, 2009 I always make it a practice to not use back ticks. Back ticks aren't compatible with other SQL dialects, and they aren't needed unless you're using reserved words. Link to comment https://forums.phpfreaks.com/topic/145181-problem-in-select-query/#findComment-762216 Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 Back ticks aren't compatible with other SQL dialects That's what abstraction is for. Link to comment https://forums.phpfreaks.com/topic/145181-problem-in-select-query/#findComment-762220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.