[SOLVED]PHp/MySQL Question
Posted: Mon Jun 20, 2005 9:18 am
On a form, how can I get the results to be echoed out with the newest being first instead of the oldest first? I went to MySQL.org to see if I could figure out Order By function, but I couldn't get it to work.
Here is what I have:
Stories.php
Insert.php
Here is what I have:
Code: Select all
CREATE TABLE `tblstory` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`title` text NOT NULL,
`story` text NOT NULL,
`time` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;Code: Select all
<?php
$username="rlzcjewc_danaweb";
$password="dana5899";
$database="rlzcjewc_danastories";
$link = mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die("Unable to select database");
$query = mysql_query("SELECT name,title,story,time FROM tblstory WHERE id>0",$link);
while($row = mysql_fetch_row($query)) {
$dateis = date("m/d/Y", $row[3]);
echo "<b>".$row[1]."</b>";
echo "<br>".$row[2];
echo "<br><br>".$row[0].", ".$dateis;
echo "<br><br><img src=images/break.gif><br><br>";
}//end while.
?>Code: Select all
<?
$username="rlzcjewc_danaweb";
$password="dana5899";
$database="rlzcjewc_danastories";
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die("Unable to select database");
if($name==""){
echo "you didn't enter a name!";
exit();}
elseif($title==""){
echo "you didn't enter a title!";
exit();}
elseif($story==""){
echo "you didn't enter a story!";
exit();}
else{
$timePosted = time();
$query = "insert into tblstory (name,title,story,time) values ('$name','$title','$story','$timePosted')";
echo "story added! you are being redirected";
}
$result = mysql_query($query) or die(mysql_error());
mysql_close();
?>
<meta http-equiv="refresh" content="1;url=stories.php">