co.ador Posted April 10, 2011 Share Posted April 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233282-need-help-joining-tables-fields-through-a-relational-database/ Share on other sites More sharing options...
BlueSkyIS Posted April 10, 2011 Share Posted April 10, 2011 what do you mean by "not working?" what is happening or isn't happening. and show more than one line of code, if possible. Quote Link to comment https://forums.phpfreaks.com/topic/233282-need-help-joining-tables-fields-through-a-relational-database/#findComment-1199708 Share on other sites More sharing options...
Zurev Posted April 10, 2011 Share Posted April 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/233282-need-help-joining-tables-fields-through-a-relational-database/#findComment-1199710 Share on other sites More sharing options...
co.ador Posted April 10, 2011 Author Share Posted April 10, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233282-need-help-joining-tables-fields-through-a-relational-database/#findComment-1199729 Share on other sites More sharing options...
co.ador Posted April 10, 2011 Author Share Posted April 10, 2011 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/233282-need-help-joining-tables-fields-through-a-relational-database/#findComment-1199785 Share on other sites More sharing options...
spiderwell Posted April 10, 2011 Share Posted April 10, 2011 put the full names in the join section, SELECT * FROM <Table1>, <Table2> WHERE (Table1.column = Table2.column) Quote Link to comment https://forums.phpfreaks.com/topic/233282-need-help-joining-tables-fields-through-a-relational-database/#findComment-1199791 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.