Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

SQL 101 question - this is really easy


paulrus

Recommended Posts

Hi guys.

 

Ok, I have the following SQL query:

 

$sqlcount = "SELECT * FROM `products` ORDER BY 'products_model'";

$sql = "SELECT * FROM `products` ORDER BY 'products_model' LIMIT $pl, $num_products";

 

Now... I want this query to only select records from one particular manufacturer. Can anyone tell me how I should modify this query to select only one maker?

 

Thanks!

 

Paul

Link to comment
Share on other sites

I just got your email and replied.

 

But what you want to do is this:

 

$sqlcount = "SELECT * FROM `products` ORDER BY 'products_model' WHERE manufacturers_id = 'x'";

$sql = "SELECT * FROM `products` ORDER BY 'products_model' LIMIT $pl, $num_products WHERE manufacturers_id = 'x'";

 

Make sure you replace x for your manufacturer id number.

 

Patrick

Patrick

Link to comment
Share on other sites

"Order by" and Limit clause should always be after where clause.

 

$sqlcount = "SELECT * FROM `products` ORDER BY 'products_model' WHERE manufacturers_id = 'x'";  

Should be:

$sqlcount = "SELECT * FROM `products` WHERE manufacturers_id = x ORDER BY products_model";

 

$sql = "SELECT * FROM `products` ORDER BY 'products_model' LIMIT $pl, $num_products WHERE manufacturers_id = 'x'";  

should be:

 

$sql = "SELECT * FROM `products` WHERE manufacturers_id = x ORDER BY 'products_model' LIMIT $pl, $num_products ";

Kenneth Wang

VA3RRW/BD4RR

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...