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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites


<?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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.