knox203 Posted April 22, 2008 Share Posted April 22, 2008 Hello all! I'm wondering a good way to grab the first and last day out of a query. I need to pass these on to my fpdf app to supply a date range. I.E. - I have 36 rows returned ranging from 2008-03-01 - 2008-03-31, I would want to grab 2008-03-01 and 2008-03-31 as two separate values. Here's the code I'm working with: <? $ic = "select id, driver, date, job, customer, pay_period, round(base,2) as base_round, round(paid,2) as paid_round FROM test.commission_report WHERE driver = '". $_POST['username']. "' and SUBSTRING(date, 6, 2) = '". $_POST['month']. "' and pay_period = '". $_POST['payperiod']. "' group by id, SUBSTRING(date, 6, 2)"; echo "<!-- $ic -->\r\n"; $ic_result = mysql_query($ic) or die (mysql_error()); $fields = mysql_fetch_assoc($ic_result); $paid_total = array(); $base_total = array(); $row_counter = 1; do { $paid_total[] = $fields['paid_round']; $base_total[] = $fields['base_round']; $newdate = $fields['first_date']; $driver = ereg_replace("99", "C", $fields['driver']); $row_counter++; ?> Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 22, 2008 Share Posted April 22, 2008 you could run 2 queries like this: <?php $first = mysql_query("SELECT date FROM table ORDER BY date ASC LIMIT 1")or die(mysql_error()); $second = mysql_query("SELECT date FROM table ORDER BY date DESC LIMIT 1")or die(mysql_error()); $first_date = mysql_fetch_object($first); $second_date = mysql_fetch_object($second); $date_one = $first_date->date; $date_two = $second_date->date; echo "$date_one - $date_two"; ?> EDIT: oops, I left something out in the code, try it now Quote Link to comment Share on other sites More sharing options...
knox203 Posted April 22, 2008 Author Share Posted April 22, 2008 Your code led me through a couple modifications to the perfect solution. Thanks a ton, Northern Flame!! Quote Link to comment 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.