Jump to content

need help joining tables fields through a relational database


co.ador

Recommended Posts

I have a relational table call sales with prodcut_id and custmer_id tables. I also have a product and customer tables. products table with product_id as an auto increment and customer with custumer_id I want to join through the sales tables all t he fields of row 1 from tables customer and products and pull it at once.

 

 

This is a member login script and I want to display the products by members.

 

So far I have this query to display the products once the member is login in. $userid is the id of the customer coming from the $userid= $_SESSION['customer_id'];

 

 

$mysqlSales="SELECT products.* FROM products JOIN sales ON (products.product_id = procuct_id ) WHERE sales.customer_id = '$userid'";

 

 

so far that statement is not working where should I have some type of incoherance with the english statement above expressing what I want the query to do.

I believe when you use join ON it implies the two equal each other, and you're join ON field can be the matching column name, I may be wrong though, try:

$mysqlSales="SELECT products.* FROM products JOIN sales ON ( product_id ) WHERE sales.customer_id = '$userid'";

 

Also, you spell product like 3 different ways in your post.

I believe when you use join ON it implies the two equal each other, and you're join ON field can be the matching column name, I may be wrong though, try:

$mysqlSales="SELECT products.* FROM products JOIN sales ON ( product_id ) WHERE sales.customer_id = '$userid'";

 

Also, you spell product like 3 different ways in your post.

 

is not pulling any data at all.

 

I will try that zurev feedback on that later


<?php 
$mysqlSales="SELECT * FROM products INNER JOIN sales  ON product_id  WHERE customer_id = '$userid' ";
$productCount = mysql_num_rows($mysqlSales); 
if ($productCount>0 )
     {
     while($row = mysql_fetch_array($mysqlSales))
?>

 

 

Query statement above is throwing a warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

 

what could that be?

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.