selecting the most recent
Moderator: General Moderators
selecting the most recent
hey well on my site for the most recent news i have a form which goes to my database that works fine but i want to have the most recent in box one below and the second most recent in the box marked 2 and the 3 and fourth in the boxes marked 3 and 4
___ ___
| 1 | 2 |
|__|__|
| 3 | 4 |
|__|__|
and wen i add a new record i want number 4 to go an 3 to move into 4 2 into 3 1 into 2 and the new one in 1 anyone now how im new at PHP if anyone could help id be very greatfull
thank....
___ ___
| 1 | 2 |
|__|__|
| 3 | 4 |
|__|__|
and wen i add a new record i want number 4 to go an 3 to move into 4 2 into 3 1 into 2 and the new one in 1 anyone now how im new at PHP if anyone could help id be very greatfull
thank....
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
a combo of +[php_man]array_reverse[/php_man]() and some math in volving % (modulous) could do this easy.
Code: Select all
ORDER BY somefield DESC LIMIT 4i tried that :(
i tried that but becus of the layout it dont work i have to put that thing in each box but how do i get each one to select the 2nd 3rd and 4th most recent alone ?
ok your probably beina great help but i dont get any of it sorry
can someone give like a script iv jus been tryin
<?php
$conn = mysql_connect("localhost", "name", "pass");
mysql_select_db("database", $conn);
$update1 = mysql_query("SELECT date, comments FROM news order by id desc limit 0,1");
while ($row = mysql_fetch_row($update1))
{
print("
<ul>
<li>
$row[1]
</li>
</ul>
<p>On : <b>$row[0]</b></font>
");
}
?>
and ive been tryin to adjust the limit ? :S ? but i realy dont no how to do it hep need urgently
<?php
$conn = mysql_connect("localhost", "name", "pass");
mysql_select_db("database", $conn);
$update1 = mysql_query("SELECT date, comments FROM news order by id desc limit 0,1");
while ($row = mysql_fetch_row($update1))
{
print("
<ul>
<li>
$row[1]
</li>
</ul>
<p>On : <b>$row[0]</b></font>
");
}
?>
and ive been tryin to adjust the limit ? :S ? but i realy dont no how to do it hep need urgently
Say you wanted 5 records to be shown from the query, just write:
Code: Select all
$update1 = mysql_query("SELECT date, comments FROM news ORDER BY id DESC LIMIT 5");You should add a new column named 'unixtimestamp' and when 'INSERTING' into the database use:
Where headline and news is the actual news content and where $time is the unix timestamp: list($utime, $time) = explode(" ", microtime());
You should then make the query like:
Code: Select all
list($utime, $time) = explode(" ", microtime());
$query = "INSERT INTO news VALUES('$headline','$news','$time')";You should then make the query like:
Code: Select all
$update1 = mysql_query("SELECT * FROM news ORDER BY unixtimestamp DESC");