August 25th, 2000, 01:28 PM
Hi guys. I'm Henry from Argentina.
You know that by making this:
//$table, $id comes from a form.php3 with some values
$result=mysql_db_query("$db","select * from $table where id=$id);
//the i gotta type this
//i must show all data from $table
BUT... what happens if i wanna show the data in inverse order than the order that the table has. This idea came up to mi mind cause i've a $table with messages posted by users, so i wanna show the newest message first and the oldest at bottom...
With this while i've shown you, the oldest appears first... What can i do ?
I send ya the structure of my table:
the id field can contain 3 types. If message id is 1 i must show this message in one part of the page, if 2, in other section, and if the message id is 3 i must show in another section, but i must always show the newest message at top of the section. Could i add another field to the table, so i can generate a better algorithm for making this possible ?
Thanks in advance. See ya.
Henry - Argentina
August 25th, 2000, 01:34 PM
You should be able to add a field with date and toime submitted then could add another clause to your select statement like:
$result=mysql_db_query("$db","select * from $table where id=$id ORDER by date desc);
August 25th, 2000, 01:40 PM
If I get this right you have 3 sections where messages can be showed and each section has to have the newest at the top?
I would rename the current column 'id' to 'section' and add another column in your database called 'id', which is auto incrementing (so the latest message has the highest id)
Then make the following query:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
$table = ""; // whatever you use
$section = '1'; // for section 1
$result = mysql_query( "SELECT * FROM $table WHERE section='$section' ORDER BY id DESC" );
The message with the highest id (also the newest) will be shown first...