display the contents of MySql Blog

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

display the contents of MySql Blog

Post by ericburnard »

Hi there. i have been trying to write a blog script and have so far managed to get it to write to my database but i dont know how to make all of the posts diplayed.

how can i do it where i can just put $subject in the right place in the template to make it post the subject??

thanks again
eric
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

need to select off the database you will. Loop the results you should. Display any fields you can.

Code: Select all

$query = "select * from myBlogTable";
$result = mysql_query($query)
  or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
  echo $row['subject']."<br>";
} // end while for result set
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

That puts in all of the subjetcs tho.
i am wanting it a bit like this -

Blog entry subject ($subject)

Blog Message ($message)

$date :: [$time]

then the same again underneath for the next blog entry

thanks again

Eric
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

then inject some html you should:

Code: Select all

echo "<table>";
while($row = mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$row['subject']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>".$row['message']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>".date("m/d/Y", strtotime($row['date']))."</td>";
echo "</tr>";
//etc
} // end while for result set
Post Reply