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
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!

 

 

Link to comment
Share on other sites

<?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.";
  }
?>

Link to comment
Share on other sites

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)){

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.