87dave87 Posted October 23, 2006 Share Posted October 23, 2006 Hi,This is my page which displays data in one of my database tables: -http://www.emulators.cc/windows/atari2600/test.phpAs you can see, the rows are listed by the rating (im not sure how its done this - is this because there is more text in the rating field as there is more html code for each star?). If the rating is the same as another row I then want the rows displayed in order of rating and which is the most up to date record.At the moment it is not recognizing the year in the date field.The php code for the above page is: -<?php $database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database");$sql = mysql_query("SELECT emulator, version, DATE_FORMAT(updated, '%d %b %Y') AS updated, rating, readme, screenshot, download FROM windows_atari2600 order by rating desc, updated desc");while ($get_info = mysql_fetch_row($sql)) { echo "<tr>"; foreach ($get_info as $field) echo "<td>$field</td>\n"; echo "</tr>\n";}?> Link to comment https://forums.phpfreaks.com/topic/24834-displaying-row-by-rating-and-date/ Share on other sites More sharing options...
obsidian Posted October 23, 2006 Share Posted October 23, 2006 well, since you're selecting your date_format as 'updated', you're overloading that column name, and the order by is sorting based on the string result. you need to name the formatted date a different name so you can still order by updated. Link to comment https://forums.phpfreaks.com/topic/24834-displaying-row-by-rating-and-date/#findComment-113098 Share on other sites More sharing options...
87dave87 Posted October 23, 2006 Author Share Posted October 23, 2006 Ok, ive done that and it works: -<?php $database="irrm3a_emulators"; mysql_connect ("localhost", "irrm3a", "reallydo3t"); @mysql_select_db($database) or die( "Unable to select database");$sql = mysql_query("SELECT emulator, version, DATE_FORMAT(updated, '%d %b %Y') AS newupdated, rating, readme, screenshot, download FROM windows_atari2600 order by rating desc, updated desc");while ($get_info = mysql_fetch_row($sql)) { echo "<tr>"; foreach ($get_info as $field) echo "<td>$field</td>\n"; echo "</tr>\n";}?>Do I really need the AS newupdated part? Its not actually doing anything is it? Link to comment https://forums.phpfreaks.com/topic/24834-displaying-row-by-rating-and-date/#findComment-113101 Share on other sites More sharing options...
obsidian Posted October 23, 2006 Share Posted October 23, 2006 the "AS newupdated" is simply renaming the column you pull out. you then can use the 'newupdated' result in your script to display the formatted date. Link to comment https://forums.phpfreaks.com/topic/24834-displaying-row-by-rating-and-date/#findComment-113107 Share on other sites More sharing options...
87dave87 Posted October 23, 2006 Author Share Posted October 23, 2006 Ok, but when I display 'updated' after the date format its already changed, and as I dont use newupdated.. it can be removed. Link to comment https://forums.phpfreaks.com/topic/24834-displaying-row-by-rating-and-date/#findComment-113109 Share on other sites More sharing options...
obsidian Posted October 23, 2006 Share Posted October 23, 2006 [quote author=87dave87 link=topic=112427.msg456263#msg456263 date=1161608717]Ok, but when I display 'updated' after the date format its already changed, and as I dont use newupdated.. it can be removed.[/quote]sure. what i posted above is the only advantage to renaming a column. otherwise, it's completely optional. if you're not using the formatted date, you can actually remove the whole DATE_FORMAT function and only select updated by itself. Link to comment https://forums.phpfreaks.com/topic/24834-displaying-row-by-rating-and-date/#findComment-113115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.