Jump to content

PHP/MYSQL Left Join problem


SocomNegotiator

Recommended Posts

Ok well I am trying to grab information from two tables based on the info. in one table. So there are three tables involved. I have a user table, item table, and a pre_order table. The pre_order table has the item_id, user_id, and amount/quantity. Now I want to take those fields and use a left join so I can create a page that will show the user what they have in "their cart" essentially. Here is what I have...

 

<?php
$user_id = $user->inf['id'];
$lname = $user->inf['last_name'];
$db->query('SELECT docj_user.id, item.id, item.name, item.description, pre_order.amount FROM pre_order LEFT JOIN item ON pre_order.item_id = item.id LEFT JOIN docj_user ON pre_order.user_id = docj_user.id') or die(mysql_error());
$count = $db->num_rows();

if ($count == 0)	{
	echo "<br /><div id='case'><p align='center' style='color: red;'>You have no orders to view.</p></div>";
}

?>

<style type="text/css">
.menu22 ul{
        margin: 0px; padding: 0px;
        float: left;}

.menu22 ul li{
        display: inline;
	margin:2px 5px 5px 20px;}

</style>

<div class="menu22" align="left">
<ul>

<?php


while($row = $db->fetch_array())	{
	?>
		<form id='order_form' action='?page=view_item' method='post'><input type='hidden' name='user_id' value='<?=$row['docj_user.id']?>'/>
		<li>
			<ul style="width: 200px; height: 125px;">
				<li>Item Name: <?=$row['item.name']?></li><br />
				<li>Description: <?=$row['item.description']?></li><br />
				<li>Quantity: <?=$row['pre_order.amount']?></li>
			</ul>
		</li>

		</form>
	<?php
}
?>
</ul>
<br style="clear: left" />
</div>

 

 

Now the code here brings up the correct amount of fields that user has because of the count variable I have. However, it is not bringing up the docj_user.id for the hidden field or any of the variables for the list. Any ideas would be much appreciated. Thanks

Link to comment
https://forums.phpfreaks.com/topic/115135-phpmysql-left-join-problem/
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.