Jump to content

Inner join problems???


cturner

Recommended Posts

I am trying to display database items from two different tables. When I test the following code nothing displays. Can someone please tell me how I can fix this problem? Thanks in advance.

[code=php:0]
require "config.php";
$query2 = "SELECT * FROM tbl_product INNER JOIN tbl_cart ON tbl_product.productname = tbl_cart.username";
$r2 = mysql_query($query2) or die('Could not query because3: ' .mysql_error());
while($row2 = mysql_fetch_array($r2)){
// display the product name
echo "<td valign=top>".$row2['productname']."<br />";
// display the options
echo $row2['packsize']."<br />";
echo $row2['colour']."<br />";
echo $row2['icon']."<br />";
echo $row2['name']."<br />";
echo $row2['address1']."<br />";
echo $row2['address2']."<br />";
echo $row2['address3']."<br />";
echo $row2['address4']."<br />";
echo $row2['address5']."<br />";
echo "</td>";
}
mysql_close();
[/code]
Link to comment
https://forums.phpfreaks.com/topic/26187-inner-join-problems/
Share on other sites

It looks ok off hand. Are you sure you have data that match in BOTH tables? If you expect data back even if one table doesn't match, then you should be using a LEFT/RIGHT JOIN instead.

Try running the query at the MySQL command prompt or GUI, etc. Experiment with a WHERE clause and see.

Post some sample data you have in both tables if you're still having problems.
Link to comment
https://forums.phpfreaks.com/topic/26187-inner-join-problems/#findComment-119812
Share on other sites

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.