Forum Moderators: coopster

Message Too Old, No Replies

Searching for the smallest date value in an array

Array contains dates, need the smallest date

         

Mitch888

7:51 pm on Mar 5, 2003 (gmt 0)

10+ Year Member



$sql="Select *from results where user_id ='$user_id'";

$result = $db->EXECUTE($sql);
$c1 = mysql_fetch_array($result);

while($c1 = mysql_fetch_array($result)){
echo "$c1[date]<br>";
}

that way I get all the dates i.e.
2003-01-28
2003-05-24
2003-07-11
2003-07-13

I need to get the smallest date $C1[date] which is "2003-01-28" how can I assign it to a $variable?

please help

thank you

jatar_k

8:07 pm on Mar 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what about a different sql satement?

$sql2 = Select min(date) as theone from results where user_id ='$user_id'
$q = mysql_query($sql2);
$qr = mysql_fetch_array($q);
$smallestdate = $qr['theone'];

take a look at
Functions for Use with GROUP BY Clauses [mysql.com]

Mitch888

12:59 am on Mar 6, 2003 (gmt 0)

10+ Year Member



it worked.

thank you very much