Jump to content

Problem in select query


aruns

Recommended Posts

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

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.

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. :)

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.