Jump to content

Why Does my PHP miss a value from my DB ?


vincej

Recommended Posts

I am trying to find the order values between 2 dates: $date1 and $date2. My code appears to work BUT, for some reason it always leaves out one of the values from my MySQL DB table. I have checked in the table that the Time value of the order being left out is indeed within the date range and yup it sure it, but for some crazy reason it is either not being picked up by the sql statement or the PHP statement or something -  I just don't get it > there must be a stupid error somewhere

 

Many Many Thanks for your help - Vincej

 

 

 

 


/* Create Query*/
<?php
$query_sales_shipping_tax = "SELECT order_id, user_id, order_tax, order_shipping_tax, cdate FROM jos_vm_orders ORDER BY cdate DESC";
$sales_shipping_tax = mysql_query($query_sales_shipping_tax, $teashop) or die(mysql_error());
$row_sales_shipping_tax = mysql_fetch_assoc($sales_shipping_tax);
?>

/*Create dates for start and end of range 	*/	
<?php
$date1 = strtotime("09/30/2010");
$date2 = strtotime("10/05/2010");
?>
<br />


/*Create While statement Create Conditions & Echo results*/ 

<?php
while ($row_sales_shipping_tax = mysql_fetch_assoc($sales_shipping_tax)){
if ($row_sales_shipping_tax['cdate']  >$date1 && $row_sales_shipping_tax['cdate']  <$date2){?>

		<tr>
            <td><?php echo $row_sales_shipping_tax['order_id']; ?></td>
            <td><?php echo $row_sales_shipping_tax['user_id']; ?></td>
            <td><?php echo strftime("%m/%d/%Y/%H/%M/%S", $row_sales_shipping_tax['cdate']); ?></td>
            <td><?php echo $row_sales_shipping_tax['order_tax']; ?></td>
            <td><?php echo $row_sales_shipping_tax['order_shipping_tax']; ?></td>
            </tr>


<?php }	

 

 

Link to comment
Share on other sites

because you do this once, before doing it again within a loop:

 

$row_sales_shipping_tax = mysql_fetch_assoc($sales_shipping_tax); // pull off first row of data

// ... then later
while ($row_sales_shipping_tax = mysql_fetch_assoc($sales_shipping_tax)){ // starts with second row

Link to comment
Share on other sites

Dreamweaver is notorious for doing this.

 

It is as BlueSky states.  You are calling mysql_fetch_assoc which increments your array data pointer by 1, then you follow it up later with another call.  This second call doesn't reset the data pointer.  So you miss your first row of data.  Take out the first data call, as it is not needed or used.

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.