A Few Quick Questions
Moderator: General Moderators
-
JBrown1045
- Forum Newbie
- Posts: 10
- Joined: Sun Jun 19, 2005 1:19 pm
A Few Quick Questions
hello:
I am very new to PHP. I know some coding, but a few I am not aware of.
On the page danaplatoforever.com/stories.php what code can I use to get the stories to be posted with the newest coming up first?
Secondly on danaplatoforever.com/mmesages.php it keeps showing the date 12/31/1969. WHat am I doing wrong?
Thanks in advance.
Jonathan
I am very new to PHP. I know some coding, but a few I am not aware of.
On the page danaplatoforever.com/stories.php what code can I use to get the stories to be posted with the newest coming up first?
Secondly on danaplatoforever.com/mmesages.php it keeps showing the date 12/31/1969. WHat am I doing wrong?
Thanks in advance.
Jonathan
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
the message being newest first:
you need a larger description on how the thing runs at the moment, are each of the stories in individual txt files or are they in the same txt file. If they are in the same file you can explode() the file after reverse_array() the order.
If that is no help you may need to give a more in depth description,
you need a larger description on how the thing runs at the moment, are each of the stories in individual txt files or are they in the same txt file. If they are in the same file you can explode() the file after reverse_array() the order.
If that is no help you may need to give a more in depth description,
-
JBrown1045
- Forum Newbie
- Posts: 10
- Joined: Sun Jun 19, 2005 1:19 pm
I don't have them in any txt fils. I I have them in a database and have them choed to the site from database.andylyon87 wrote:the message being newest first:
you need a larger description on how the thing runs at the moment, are each of the stories in individual txt files or are they in the same txt file. If they are in the same file you can explode() the file after reverse_array() the order.
If that is no help you may need to give a more in depth description,
there are two solution, one PHP one, one in SQL.
PHP has been described above, in SQL you simply change the statement using "ORDER BY".
Assuming you have timestamp field in your db-table (in the statement below called "date")
PHP has been described above, in SQL you simply change the statement using "ORDER BY".
Assuming you have timestamp field in your db-table (in the statement below called "date")
Code: Select all
SELECT id, author, title, date... FROM ... WHERE ... ORDER BY date ASC LIMIT 0,10Probably. Let's seetimvw wrote:probably want to have a look at functions like DATE_FORMAT for MySQL... Instead of performing a php call to date for every row...
Code: Select all
$query = mysql_query("e;SELECT name,message,time FROM tblmessages WHERE id>0 ORDER BY time ASC LIMIT 0,10"e;,$link);This
Code: Select all
$query = mysql_query("e;SELECT name,message,time FROM tblmessages ORDER BY time ASC LIMIT 0,10"e;,$link);-
JBrown1045
- Forum Newbie
- Posts: 10
- Joined: Sun Jun 19, 2005 1:19 pm
Neither worked. They kept the form together with no error but still posted them in oldest first.patrikG wrote:Probably. Let's seetimvw wrote:probably want to have a look at functions like DATE_FORMAT for MySQL... Instead of performing a php call to date for every row...
You most probably don't need "WHERE id>0" as that will probably be an autoincrementing field and won't have a negative value.Code: Select all
$query = mysql_query("e;SELECT name,message,time FROM tblmessages WHERE id>0 ORDER BY time ASC LIMIT 0,10"e;,$link);
Thisshould do as well.Code: Select all
$query = mysql_query("e;SELECT name,message,time FROM tblmessages ORDER BY time ASC LIMIT 0,10"e;,$link);
-
JBrown1045
- Forum Newbie
- Posts: 10
- Joined: Sun Jun 19, 2005 1:19 pm
Table is set up like this:patrikG wrote:does table have timestamp column (datetime)? If not, it won't work. See my first post.
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 ;- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
JBrown1045
- Forum Newbie
- Posts: 10
- Joined: Sun Jun 19, 2005 1:19 pm
my time fields? I only have one. It just is suppose to show Month/Day/Year The form works it just keeps echoing wrong. This may help you out:Jcart wrote:What do your time fields look like? Are they being inputted correctly?
My table:
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
<form method="post" action="insert2.php" name="this">
<table width="100%" cellpadding="2" cellspacing="1">
<tr><td align="right"><font size="2" color="#0076ec">Name:</font></td><td><input type="text" name="name" maxlength="18" value=""></td></tr>
<tr><td align="right" valign="top"><font size="2" color="#0076ec">Message:</font></td><td><textarea name="message" class="entry" cols="25" rows="6"></textarea></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="sendstory" value="Send Message"></td></tr>
</table>
</form>
<BR><FONT size=5><FONT color=#0076ec><B>Messages For Dana</B></FONT><br><img src=images/break.gif><br> </center>
<font size="2">
<?php
$username="rlzcjewc_danaweb";
$password="dana5899";
$database="rlzcjewc_danamessages";
$link = mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die("Unable to select database");
$query = mysql_query("SELECT name,message,time FROM tblmessages WHERE id>0",$link);
while($row = mysql_fetch_row($query)) {
$dateis = date("m/d/Y", $row[3]);
echo "<b>".$row[1]."</b>";
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_danamessages";
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($message==""){
echo "you didn't enter a message!";
exit();}
else{
$timePosted = time();
$query = "insert into tblmessages (name,message,time) values ('$name','$message','$timePosted')";
echo "message added! you are being redirected";
}
$result = mysql_query($query) or die(mysql_error());
mysql_close();
?>
<meta http-equiv="refresh" content="1;url=mmessages.php">Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
on mmessage.php change
to
Code: Select all
$query = mysql_query("SELECT name,message,time FROM tblmessages WHERE id>0",$link);
while($row = mysql_fetch_row($query)) {
$dateis = date("m/d/Y", $row[3]);
}Code: Select all
$query = mysql_query("SELECT name,message,time FROM tblmessages WHERE id>0",$link);
while($row = mysql_fetch_array($query)) {
$dateis = date("m/d/Y", $row[2]);
}-
JBrown1045
- Forum Newbie
- Posts: 10
- Joined: Sun Jun 19, 2005 1:19 pm
good call it worked perfectly. Any chance you know what to do to get teh database to echo the newest post first?Jcart wrote:on mmessage.php change
toCode: Select all
$query = mysql_query("e;SELECT name,message,time FROM tblmessages WHERE id>0"e;,$link); while($row = mysql_fetch_row($query)) { $dateis = date("e;m/d/Y"e;, $rowї3]); }
Code: Select all
$query = mysql_query("SELECT name,message,time FROM tblmessages WHERE id>0",$link); while($row = mysql_fetch_array($query)) { $dateis = date("m/d/Y", $row[2]); }