vincej Posted February 2, 2011 Share Posted February 2, 2011 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 } Quote Link to comment https://forums.phpfreaks.com/topic/226416-why-does-my-php-miss-a-value-from-my-db/ Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/226416-why-does-my-php-miss-a-value-from-my-db/#findComment-1168658 Share on other sites More sharing options...
jcbones Posted February 2, 2011 Share Posted February 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226416-why-does-my-php-miss-a-value-from-my-db/#findComment-1168676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.