Hi,

I am designing a E-commerce site. I have designed a way for the customers to view their previous orders, but for some reason there is a problem.

The codes that you see below work but the while loop keeps stopping at 2 items when there should be more.

Can someone please help me debug.

Thanks

<?php require("header.php"); 
$order_history = mysql_query("SELECT * FROM order_items WHERE orderitems_cust_id = ". $_SESSION['SESS_USERID']." AND order_items_order_id = ". $_GET['id']." AND order_history = 'Y'");
						$order_total = mysql_fetch_assoc(mysql_query("SELECT * FROM order_total WHERE order_id = ".$_GET['id']." AND cust_id = ". $_SESSION['SESS_USERID']));
						$o_row = mysql_num_rows($order_history);
?>         
         <div id="padding-middle">Order History</div>
                <div id="padding-text">
                <div class="smaller_text"> &laquo; <a class="logtext" href="account.php">My Account</a></div>
<p class="middle-header">Order Detail - Invoice LPPS_<?php echo $_GET['id']; ?></p>
                    <table width="500" border="0" cellspacing="5" cellpadding="5">
                      <tr>
                        <th width="120" align="left" valign="top" scope="row">Invoice Number</th>
                        <td>LPPS_<?php echo $_GET['id']; ?></td>
                      </tr>
                      <tr>
                        <th width="120" align="left" valign="top" scope="row">Date of Order</th>
                        <td><?php $date = mysql_fetch_assoc($order_history); echo $date['order_date']; ?></td>
                      </tr>
                      <tr>
                        <th width="120" align="left" valign="top" scope="row">Payment Type</th>
                        <td>PayPal</td>
                      </tr>
                      <tr>
                        <th width="120" align="left" valign="top" scope="row">Address</th>
                        <td><?php $ua = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE users_id = ". $_SESSION['SESS_USERID'])); echo $ua['fname'].' '.$ua['lname'];
							echo '<br />'.$ua['street'].'<br />';
							echo $ua['city'].', '.$ua['state'].' '.$ua['zipcode'];?></td>
                      </tr>
                      <tr>
                        <th width="120" align="left" valign="top" scope="row">Status</th>
                        <td style="color:"><?php 
								if($order_total['status'] == 1) 
								{  
									echo '<div class="status_1">Processing Order...<span class="smaller_text">Once payment has been confirmed your order will be shipped within 5-7 business days (not including weekends).</span></div>';
								}
								if($order_total['status'] == 2) 
								{  
									echo '<div class="status_2">Order has been confirmed/shipped! <span class="smaller_text">If you have any questions about your order please fill out the <a class="logtext" href="contact.php">Contact Us Form</a>. Thanks!</span></div>';
								}
								?>
                        </td>
                      </tr>
</table>

                    
                    <?php 
						
			if($o_row == 0)
				{
					echo '<em>No Invoices Available</em>';
				}
				else
				{	
?>	
<p class="middle-header">Purchase</p>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <th scope="col" class="cart-cell-header">Product</th>
    <th scope="col" class="cart-cell-header">Product Name and Description</th>
    <th scope="col" class="cart-cell-header">Quantity</th>
    <th scope="col" class="cart-cell-header">Original Price</th>
    <th scope="col" class="cart-cell-header">Total</th>
  </tr>
<?php
while($o = mysql_fetch_assoc($order_history))
	{

?>



  
<?php  
		$otc = $o['orderitems_prod_id'];
		//Selecting the product number from products then find the orginal price of the item
		$ot = mysql_fetch_assoc(mysql_query("SELECT * FROM products WHERE prod_id = $otc"));
		$cat_id = $ot['prodcat_id'];
		$c = mysql_fetch_assoc(mysql_query("SELECT * FROM categories WHERE cat_id = $cat_id"));
		//Inside Layout starts here
?>

  <tr>
    <td class="IMAGE">
    	<?php 
			 if($ot['prod_img'] == NULL)
		{
			echo '<img class="cart-img" src="placeholder/image.jpg"><br /><br />';
		}
		else
		{
			echo '<img class="cart-img" src="'.$ot['prod_img'].'">';
		} 
		?>
    </td>
    <td class="DESC">
    	<?php 
			echo  '<strong>'.$c['cat_name'].' - '.$ot['prod_name'].'</strong><br />'.$ot['prod_desc'];
		?>
    </td>
    <td align="center" class="QUANTITY">
		<?php 
                echo  $o['orderitems_quantity'];
         ?>
    </td>
    <td class="O_PRICE">
    	<?php 
			echo '$'.$ot['prod_price'].'.00';
		 ?>
    </td>
    <td class="TOTAL">
    	<?php 
			echo  '$'.$o['orderitems_total'].'.00';
		?>
    </td>
  </tr>


<?php

	}//END OF WHILE
	?>
</table>
<?php
	echo '<div id="Total"><strong>Overall Total:</strong> $'.$order_total['order_total'].'.00</div>';

}//END OF ELSE
?>
				</div>                
<?php require("footer.php"); ?>

It's a bit messy for reading, but on line 17 is a fetch statement, that will make you miss the first record.

Ah okay, I will take a look at the codes again...

I will return a comment as soon as I review it. Thanks!

Thanks, pritaeas! It worked! =D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.