SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: sort query
-
Nov 24, 2004, 00:01 #1
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sort query
is there a way to automatically sort my table by date
at the moment all the data is pulled out with the correct username, but i want to add in there to put it into the tables according to date, either ascending or descending, doesn't bother me... can i do this, or do i have to chuck everything into arrays and then sort them out?
PHP Code:
<?php
$db = mysql_connect("localhost","root","ascs2004"); //connect to mysql
mysql_select_db("t1",$db); //connect to db
$sql = "SELECT * from timesheet"; //connect to table
$result = mysql_query($sql, $db) or die ("Invalid query"); //query db and catch error
echo "Previous entries for $user"; //echo username
while ($row = mysql_fetch_array($result)){ //loop through table
if ( "$row[UserID]" == "$user"){ //match usernames
//tabulate data from table
$date1 = $row['Date'];
list($y, $m, $d) = explode("-", $date1); //split date up
$date = "$d-$m-$y";
echo "<tr><td>$date</td><td>";
echo "".$row['Duties']."</td><td>";
echo "".$row['Start']."</td><td>";
echo "".$row['Break']."</td><td>";
echo "".$row['Finish']."</td><td>";
echo "".$row['TOTAL']."</td><td>";
//post values
echo "<form method =\"POST\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<input type=\"hidden\" name=\"userid\" value=\"".$row['UserID']."\">";
echo "<input type=\"hidden\" name=\"date\" value=\"".$row['Date']."\">";
echo "<input type=\"hidden\" name=\"action2\" value=\"submitted\">";
echo "<input type=\"submit\" name=\"submit2\" value=\"Delete\">";
echo "</form></tr>";
}
}
----
nick
----
i feel so stupid sometimes i really do, sorry to waste another post.
i used
PHP Code:$sql = "SELECT * FROM timesheet ORDER BY 'DATE' ASC LIMIT 0, 30";
-
Nov 24, 2004, 02:38 #2
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$sql = mysql_query("SELECT *
FROM timesheet
ORDER BY date DESC");
Bookmarks