What I want to ask is how to select from database record and my php code able to sort previous date by date,which is what i want to display in my interface:
Can't you simply use this?
SELECT `date` FROM staff WHERE `date` < NOW() ORDER BY `date`
or (if you need only different dates)
SELECT DISTINCT `date` FROM staff WHERE `date` < NOW() ORDER BY `date`
the code you need is a very simple one.
you just have to understand the meaning of the loop and "remember" state between iterations
//a variable to remember the old date
$olddate = '';
//i named this variable $sql because it actually contains an sql query
$sql = "SELECT date FROM staff WHERE date < '$Current'";
//I named this variable $res because it actually contains NOT sql query, but mysql RESource.
$res = mysql_query($sql) or treigger_error(mysql_error()." ".$sql);
//I named this variable $row because it actually represents a row from the database.
while($row=mysql_fetch_array($res)) {
if ($olddate and $olddate != $row['date']) {
echo "something here";
}
echo $row['date'];
$olddate = $row['date'];
}
("SELECT count(*), date FROM staff WHERE date < '$Current' GROUP BY date ORDER BY date asc");
Group them up with a count, you can then write out each date the number of times indicated by the count, then write out your additional value.
I think what you want can be achieved by sorting the results in the db and removing duplicates by grouping
SELECT date FROM staff WHERE date < '$Current' ORDER BY date ASC GROUP BY date;