Jump to content

[SOLVED] putting selected values in order


twixter

Recommended Posts

Hi,

 

I have a slight prob. I got this script where it displays the list of the last 5 topics by date. problem is, it does show the last 5 topics, but the newest is at the bottom of the list.

 

How can i make it show the last 5 entries, newest first?

 

Thank you!

 

 

Mae

 

 

 

 

<?

$row_count = mysql_num_rows(mysql_query("SELECT * FROM main  where topic='statement' ORDER BY date ASC")) - 5;

$result = mysql_query("
SELECT * 
FROM main where topic='statement' ORDER BY date ASC
LIMIT ".$row_count.", 5") or die("error!");

if ($result) {


while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$topic = $r["topic"];
$date = $r["date"];
$title = $r["title"];
$area = $r["area"];
$os = $r["os"];

echo " &#8226 <a href=\"view.php?id=$id&topic=$topic&date=$date&title=$title&os=$os\">$title</a> <br> "; 
}

} else {

echo "No data.";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/89479-solved-putting-selected-values-in-order/
Share on other sites

Hi awpti. I'll probably do that instead since it's the closest workaround. id is in auto_increment. thank you for your suggestion.

 

rhodesa, i'll need the newest 5 entries by date, newest one on top.

right now, what happens is like, 96, 97, 98, 99, 100 but i want it to be like 100, 99, 98, 97, 96.

 

i'll probably use ORDER BY id for the meantime.

 

Thanks too!

 

 

<?php
  $query = "SELECT * FROM `main` WHERE `topic` = 'statement' ORDER BY id DESC LIMIT 5";
  $result = mysql_query($query) or die("error!");

  if(mysql_num_rows($result){
    while ($r = mysql_fetch_array($result)) {
      $id = $r["id"];
      $topic = $r["topic"];
      $date = $r["date"];
      $title = $r["title"];
      $area = $r["area"];
      $os = $r["os"];

      echo " &#8226 <a href=\"view.php?id=$id&topic=$topic&date=$date&title=$title&os=$os\">$title</a> <br> "; 
    }
  } else {
    echo "No data.";
  }
?>

Hi Rhodesa!

 

I got this error:

 

Parse error: syntax error, unexpected '{' in /home/XXXX/public_html/statements/index.php on line 21

 

where line 21 is

  if(mysql_num_rows($result){ 

 

You're missing a closing bracket:

 if(mysql_num_rows($result)){

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.