i have made a newspage and i want the last inserted news to stand on the top of the page. like this then:
news item 4
news item 3
news item 2
news item 1
but now it is like
news item 1
news item 2
news item 3
news item 4
pls help me out.
Reversing database reading
Moderator: General Moderators
-
Z3r0Tol3ranc3
- Forum Newbie
- Posts: 7
- Joined: Mon Jul 01, 2002 11:44 am
-
Z3r0Tol3ranc3
- Forum Newbie
- Posts: 7
- Joined: Mon Jul 01, 2002 11:44 am
can you Xplain that more precycly, i'm new at PHP
some info, don't know that it helps you out
include("config.inc.php");
mysql_connect("$host","$user","$pass");
mysql_select_db("$db");
$query="SELECT * FROM news";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$query="SELECT * order by news"; then or what??
some info, don't know that it helps you out
include("config.inc.php");
mysql_connect("$host","$user","$pass");
mysql_select_db("$db");
$query="SELECT * FROM news";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$query="SELECT * order by news"; then or what??
let's assume you have an auto-increment field called 'newsId' and it is the primary index of your table.
Thendoes what you've posted because the results are ordered by the primary index in ascend-direction (default)
Then reversing the order will be done bydescending order of newsId
or you use a date/time-field. It's the same if you fill it with
INSERT INTO .... (...,datePost,...) VALUES (...,now(),...)
Then
Code: Select all
...
$result = mysql_query('SELECT topic FROM news', $conn); // or similar
while($row=mysql_fetch_row($result))
myPrintTopic($row);
...Then reversing the order will be done by
Code: Select all
...
$result = mysql_query('SELECT topic FROM news ORDER BY newsId DESC', $conn);
while($row=mysql_fetch_row($result))
myPrintTopic($row);
...or you use a date/time-field. It's the same if you fill it with
INSERT INTO .... (...,datePost,...) VALUES (...,now(),...)
Try this...
Try and use this code:
Remember that you must have an id tag which is set to primary and is also set to auto_increment. Doing so makes it a lot easier to search through and print out fields in your database.
Code: Select all
<?php
include("config.inc.php");
mysql_pconnect("$host", "$user", "$pass");
mysql_select_db("$db");
$sql = "SELECT * FROM news ORDER BY id DESC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $rowї"title"];
}
?>