Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Need help with showing multiple posts in a blog

    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/dig...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

  • #2
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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
    Last edited by G354Lyfe; 11-16-2007 at 04:52 AM.

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    Here is a cleaned up and abridged version from one of my current projects:
    PHP Code:
    $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.

  • Users who have thanked Big-Pat for this post:

    G354Lyfe (11-16-2007)

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by G354Lyfe View Post
    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/dig...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()) 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 [php][/php] tags for your code.
    Last edited by Inigoesdr; 11-16-2007 at 04:51 AM.

  • Users who have thanked Inigoesdr for this post:

    G354Lyfe (11-16-2007)

  • #5
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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
    PHP 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++)
      {
      
    $rowmysql_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.
    Last edited by G354Lyfe; 11-16-2007 at 05:06 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •