...

View Full Version : Need help with showing multiple posts in a blog



G354Lyfe
11-16-2007, 03:25 AM
I am trying to create a Content Management System with PHP and MySQL and I have run into a problem. I am having it to where the user posts a blog post and the blog post gets put onto the main page. My problem is I am wanting to have each post a user posts to show up one after the other in a descending order but the only thing I am able to do is have the new post override the old post. Do you know of anyway thats I would be able to have all the posts show up old and new? And if so would it be done in PHP or javascript? the site is http://sulley.dm.ucf.edu/~aburns/dig4716/fifth/portfolio.html if you want to try and get a better idea of what i am talking about. (you will have to register first) And if you need me to post any of the code so you can look at what I have done I can post it as well.

Im sorry if this seems very vague I tried to explain it the best I could

G354Lyfe
11-16-2007, 03:36 AM
not sure how much this will help but here is the code to the page I am tryin to get to have multiple postings

edit

Big-Pat
11-16-2007, 03:37 AM
Here is a cleaned up and abridged version from one of my current projects:


$db = new mysqli($mysql_host, $mysql_user, $mysql_password, $mysql_db);

if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
$query = 'SELECT * FROM `news` ORDER BY date DESC LIMIT 0,5';

$result = $db->query($query);

$num_results = $result->num_rows;

for ($i=0; $i<$num_results; $i++)
{
$row = $result->fetch_assoc();
echo $row['title'];
echo $row['content'];
echo $row['date'];
}
Hope that helps.

Inigoesdr
11-16-2007, 04:49 AM
I am trying to create a Content Management System with PHP and MySQL and I have run into a problem. I am having it to where the user posts a blog post and the blog post gets put onto the main page. My problem is I am wanting to have each post a user posts to show up one after the other in a descending order but the only thing I am able to do is have the new post override the old post. Do you know of anyway thats I would be able to have all the posts show up old and new? And if so would it be done in PHP or javascript? the site is http://sulley.dm.ucf.edu/~aburns/dig4716/fifth/portfolio.html if you want to try and get a better idea of what i am talking about. (you will have to register first) And if you need me to post any of the code so you can look at what I have done I can post it as well.

Im sorry if this seems very vague I tried to explain it the best I could

Couple of notes..
You shouldn't post your username and password on a public forum. When checking the username/password you should just check both at the same time, and tell people that the username and/or password is wrong if the query fails. Always clean your user input, and especially variables you insert into a query. (see mysql_real_escape_string() (http://php.net/mysql_real_escape_string)) As long as the id field in your table is set to AUTO_INCREMENT(you can change this in phpMyAdmin), you should be able to insert new rows and simply SELECT them in a decending order using a date field if you have one, or the id if you have to. You have connection code in there twice... at the top and near the middle; you only need it at the top. And finally, please use
tags for your code.

G354Lyfe
11-16-2007, 04:57 AM
k thanx to both of you. Big pat I took the code u put up and revised it to work wit my code and I got the posts to show up but there is no actual text...just the borders that are surrounding the posts

here is the code


$result = mysql_query("SELECT * FROM `cms_entries` WHERE user_id = '$user_id' AND cms_title = 'austport' ORDER BY timestamp DESC");

$num_rows = mysql_num_rows($result);
for ($i=0; $i<$num_rows; $i++)
{
$row= mysql_fetch_array($result);
echo"<div id='post'><h3 class='date'>Date: ";
echo $row["$time"];
echo"<br/>Title: ";
echo $row["$etitle"];
echo"<br/>Author: ";
echo$row["$username"];
echo"</h3><p class='postcontent'>";
echo $row["$econtent"];
echo"</p><br/></div>";
}
?>


im not sure what is wrong but I am pretty sure it has something to do with the $row=mysql_fetch_array($result)

(i also tried mysql_fetch_assoc($result) and still nuttin)

edit:
Nvm I realzied my prob...stupid mistake....thanx again guys.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum