kemper Posted April 18, 2007 Share Posted April 18, 2007 I would like to display my data but sorted by date. I have already had some postponed games, so now the results are not displaying in order of date. Suggestions are greatly appreciated. My code is below. Thank you in advance. // mySQL Table $db_con = mysql_connect(****, ****, ****) or die("Connetion to database failed!"); mysql_select_db(****); $division = $_GET['division']; $sql = "SELECT * FROM `s2007schedules` WHERE division='$division'"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; echo "<font face='Arial' size='3'>To report game results, <u> <a href='http://www.****'> <font color='#ff0000'>click here<br></font></a></u></font><br><br>\n\n"; echo "</p> <table width='100%' border='1' cellspacing='0' cellpadding='3' bordercolor='#3c64a0'>"; while ($row = mysql_fetch_array($result)) { echo "<tr> <td valign='top' width='100%'> <table border='1' width='100%' id='table1' cellspacing='0' cellpadding='2'> <tr> <td width='55%' colspan='3' bgcolor='#3c64a0'><font face='Arial' size='2' color='#ffffff'><b>" . $row['date'] . "</b></font></td> <td width='45%' colspan='2'><b><font face='Arial' size='2' color='#ff0000'> Status: </font></b><font face='Arial'>" . $row['status'] . "</font></td> </tr> <tr> <td width='2%'> </td> <td width='47%'><font face='Arial' size='2'>" . $row['visitor'] . "</font></td> <td width='6%'><font face='Arial' size='2' color='#FF0000'><center><b>" . $row['v_score'] . "</b></center></font></td> <td width='30%'><font face='Arial' size='2' color='#2b538e'><b> " . $row['time'] . "</b></font></td> <td width='15%'><font face='Arial' size='2'><center><b>Game ID:</b></center></font></td> </tr> <tr> <td width='2%'> <p align='right'><b><font face='Arial' size='2' color='#FF0000'><center>@</center></font></b></td> <td width='47%'><font face='Arial' size='2'>" . $row['home'] . "</font></td> <td width='6%'><font face='Arial' size='2' color='#FF0000'><center><b>" . $row['h_score'] . "</b></center></font></td> <td width='30%'> <a target='_blank' href=" . $row['field_link'] . "><font face='Arial' size='1' color='#ff0000'><b><u>" . $row['field'] . " " . $row['field_no'] . "</u></b></font></a></td> <td width='15%'><font face='Arial' size='1'><center>" . $row['gameid'] . "</center></font></td> </tr> </table> </td> </tr>"; } echo "</table>\n"; // mySQL ends Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/ Share on other sites More sharing options...
mpharo Posted April 18, 2007 Share Posted April 18, 2007 In your SQL table I assume you have a date field, just add an ORDER BY to your SELECT statement on the date field then add an ASC to go from first date to last or DESC to go last date to first... Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232250 Share on other sites More sharing options...
kemper Posted April 18, 2007 Author Share Posted April 18, 2007 I do have a date field. How do I what you are suggesting? I have not heard of that yet. Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232254 Share on other sites More sharing options...
mpharo Posted April 18, 2007 Share Posted April 18, 2007 SELECT * FROM table WHERE field='$var' ORDER BY datefield ASC Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232259 Share on other sites More sharing options...
kemper Posted April 18, 2007 Author Share Posted April 18, 2007 So... My satetement is: $sql = "SELECT * FROM `s2007schedules` WHERE division='$division'"; Can I add it to my statement? Would it be: $sql = "SELECT * FROM `s2007schedules` WHERE division='$division' WHERE field='$date' ORDER BY datefield ASC"; Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232267 Share on other sites More sharing options...
mpharo Posted April 18, 2007 Share Posted April 18, 2007 You have 2 Where statements in there, that wont work at all...try this... $sql = "SELECT * FROM `s2007schedules` WHERE division='$division' ORDER BY datefield ASC"; you must replace datefield with the field that contains your dates in your table Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232278 Share on other sites More sharing options...
kemper Posted April 18, 2007 Author Share Posted April 18, 2007 That works. And that damn easy. I need to start reading more on this stuff. Thanks! Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232292 Share on other sites More sharing options...
mpharo Posted April 18, 2007 Share Posted April 18, 2007 Glad it worked... Link to comment https://forums.phpfreaks.com/topic/47574-solved-sort-by-field-date/#findComment-232295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.