• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Testing Dates

Christopher

New Member
How do you test dates?

I want to read stuff from a database and put "The newest 10" kinda thing... How do you go about doing this?
 
Assuming you are familiar with SQL, you'll form a query like ...

select * from tablename order by datefield desc limit 0,9
 
use a counter... to show the last 10 (or 20 assigned by you) records... once the counter gets to 10, exit the loop
 
Newiest posts thing:
If you want to display the 5 newiest topics do this
PHP:
<?
$query = "select * from counter order by id desc limit 5";
?>

that does not require dates at all it just orders by the id backwards. Make sure you have a column in mysql thats auto-increment
 
how would you read the results and display them. (i wanna see if the way i do it is too long)
 
okie here it is
say your table (messages) has these fields:
| id | name | email | message |

PHP:
<?
// retrieve data from MySQL database

$query = "select * from order by id desc limit 5";
$result = mysql_query($query) or die(mysql_error());

// check to see if any are exsisting

if(!$num = mysql_num_rows($result)){
echo "no data";
exit();
}

// if there is data then:

while($row = mysql_fetch_assoc($result)){
extract $row;
echo $name: $email . "<BR>";
echo $message;
}

?>
and thats that
 
Actually I was thinking of doing it that way, but would it alter the outcome if I were to delete a row? I don't think so, I use that way then. Thanx spec.
 
Back
Top