Jump to content

Displaying row by rating and date


87dave87

Recommended Posts

Hi,

This is my page which displays data in one of my database tables: -

http://www.emulators.cc/windows/atari2600/test.php

As 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
Share on other sites

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
Share on other sites

[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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.