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