5 Most Recent Posts

Discussion in 'PHP' started by caltommy69, Dec 24, 2005.

  1. #1
    I am trying to display the 5 Most recent posts - regardless of category. I got it to work, but there are a couple of bugs I need help with. The main problem is '5 of the most recent posts' will be displayed but if ONE of the '5 most recent posts' are deleted then it will only display 4 of the most recent posts. If another of the 'most recent posts' are deleted from the site. The list only shows 3. I would like it to ALWAYS show 5. Any help is greatly appreciated. If you need any other info please let me know. Thanks


    Code:

    <table border="0" align="center" cellpadding="5" cellspacing="2" width="100%">
    <tr><td class="tdmain" bgcolor="#f7f7f7"><b>Latest Postings</b></td></tr>
    <?
    $cat_sel_sql="select * from posting_details order by det_id desc limit 0,5";
    $cat_sel_result=mysql_query($cat_sel_sql);
    while($cat_sel_row=mysql_fetch_array($cat_sel_result)) {
    $cat_headid=$cat_sel_row['cat_headid'];

    $cat_sql="select * from category_head where category_head_id=$cat_headid";
    $cat_result=mysql_query($cat_sql);
    $cat_row=mysql_fetch_array($cat_result);
    $cat_headname=$cat_row['category_head_name'];
    $posting_id=$cat_sel_row['posting_id'];
    $tablename=gettablename($cat_headid);
    $post_sel_sql="select * from $tablename where verified=1 and posting_id=$posting_id order by posting_id";
    $post_sel_result=mysql_query($post_sel_sql);
    if(mysql_num_rows($post_sel_result)>0) {
    ?>
    <?
    while($post_sel_row=mysql_fetch_array($post_sel_result)) {
    ?>
    <tr><td><a href=postingdetails.php?cathead=<?=urlencode($cat_headname)?>&postingid=<?=$post_sel_row["posting_id"]?>><?=$post_sel_row["posting_title"]?>&nbsp;&nbsp;</a>(<?=$cat_headname;?>)</td></tr>
    <?
    }
    }
    }
    ?>
    </table>
     
    caltommy69, Dec 24, 2005 IP
  2. SixDeep

    SixDeep Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    one time I had to do a similar thing like this. when the form data was put into the db, I used a date&time stamp for each one. I'm sure youre doing something similar. I kept my query really simple by just calling the db field containing the date&time stamp to either sort ascending or descending. Cant remember off the top of my head. Hope this helps.
     
    SixDeep, Dec 24, 2005 IP
  3. himambo

    himambo Peon

    Messages:
    100
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $cat_sel_sql="select * from posting_details order by det_id desc limit 0,5";

    try change to this

    $cat_sel_sql="select * from posting_details order by det_id desc limit 5";
     
    himambo, Dec 26, 2005 IP