How to sort by previous date in database?

后端 未结 4 991
孤街浪徒
孤街浪徒 2021-01-16 07:46

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:



        
4条回答
  •  再見小時候
    2021-01-16 07:58

    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'];
    }
    

提交回复
热议问题