1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple thing that i dont know!

Discussion in 'PHP' started by prilep, Jan 23, 2007.

  1. #1
    Hey guys. I got a news system, but i dont know how to make it so it shows the latest news FIRST. It shows them last lol...

    $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts";
    $result = @mysql_query($query);
    
    if ($result) {
    while ($row = mysql_fetch_array($result, MYSQL_
    PHP:
    Thats the code. Can someone show me how to make it so it shows the latest news first and the oldest last. O and i need it to only show 6 news posts.

    If anyone can do that ill give green rep..

    - Prilep :D
     
    prilep, Jan 23, 2007 IP
  2. libneiz

    libneiz Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If it's an auto-increment id, just ORDER BY id DESC. You could also use the date sd.
     
    libneiz, Jan 23, 2007 IP
  3. trevlar

    trevlar Peon

    Messages:
    65
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think this should work.

    $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC";
    PHP:
     
    trevlar, Jan 23, 2007 IP
    prilep likes this.
  4. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #4

    Yes! That worked thanks. Do you know how to make it so it only shows 6 news posts. I gave you green rep for that post ill give you another one if you can figure that out.


    - Prilep :D
     
    prilep, Jan 23, 2007 IP
  5. frankcow

    frankcow Well-Known Member

    Messages:
    4,862
    Likes Received:
    264
    Best Answers:
    0
    Trophy Points:
    180
    #5
    Actually, you probably want to reference the field you're creating, so it would be:

    ORDER BY sd DESC
     
    frankcow, Jan 23, 2007 IP
  6. trevlar

    trevlar Peon

    Messages:
    65
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    
    $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 6"
    PHP:
     
    trevlar, Jan 23, 2007 IP
  7. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Thanks, that worked great! For some reason i cant give you rep again. I have to wait and give some other person rep and then i will give you.

    Thanks

    - Prilep :D
     
    prilep, Jan 23, 2007 IP
  8. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #8
    GIVING GREEN REP IF YOU SOLVE THIS!

    Ok i have a new problem. I added an image because i want an image on my news like for what the news is for but i just cant get it to show :(

    
    <?php
    include ('mysql_connect.php');
    $query = "SELECT id, title, avatar, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 2";
    $result = @mysql_query($query);
    
    if ($result) {
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $url = 'comments.php?id='.$row['id'];
    echo '
    <div id=/"right/">
    
    <img src=\"'.$row['avatar'].'\" style=\"border: 1px dashed #1079D6\" width=\"70\" height=\"70\"></a>
    <div id=/"maincontent/">
    <h3><font size="1" face="Verdana">'.$row['title'].' Íàïèøàíî ía: '.$row['sd'].'</font></h3><br />
    
    Posted by : <b>'.$row['author'].'</b><br />
    '.$row['post'].'<br />
    <a href="javascript:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>';
    }
    } else {
    echo 'There are no news posts to display';
    }
    ?>
    
    PHP:
    See everything is showed with '.$row['title'].' but i cant get the avatar to show. Maybe avatars dont show like that?? im confused..



    this is what i use for the avatar but its not showing. It gets submited into the database but dosent show
    
    <img src=\"'.$row['avatar'].'\" style=\"border: 1px dashed #1079D6\" width=\"70\" height=\"70\"></a>
    
    PHP:
    - Prilep :)
     
    prilep, Jan 23, 2007 IP
  9. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Can you post your html output code and we will be able to help.
     
    maiahost, Jan 23, 2007 IP
  10. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #10
    
    <div id=/"right/">
    
    <img src=\"'.$row['avatar'].'\" style=\"border: 1px dashed #1079D6\" width=\"70\" height=\"70\"></a>
    <div id=/"maincontent/">
    <h3><font size="1" face="Verdana">'.$row['title'].' Íàïèøàíî ía: '.$row['sd'].'</font></h3><br />
    
    Posted by : <b>'.$row['author'].'</b><br />
    '.$row['post'].'<br />
    
    
    HTML:
     
    prilep, Jan 23, 2007 IP
  11. frankcow

    frankcow Well-Known Member

    Messages:
    4,862
    Likes Received:
    264
    Best Answers:
    0
    Trophy Points:
    180
    #11
    Can you post the HTML that shows up in the browser he means
     
    frankcow, Jan 23, 2007 IP
  12. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #12
    post what you get when you try running it :) right click ->view source and the part with <img src ...
    by the way the </a> at the end is not needed I guess
     
    maiahost, Jan 23, 2007 IP
  13. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #13
    
    
    <img src=\"\" style=\"border: 1px dashed #1079D6\" width=\"70\" height=\"70\"></a>
    
    <div id=/"maincontent/">
    
    HTML:

    where it says src i just cant get it so it gets the image link... thats my problem


    thanks

    - Prilep :D
     
    prilep, Jan 23, 2007 IP
  14. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #14
    are you sure it has a value stored in it ? why don't you just echo the results like :
    
    echo 'image : '.$row["avatar"].' <br> any other values that you want to test';
    
    PHP:
     
    maiahost, Jan 23, 2007 IP
  15. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #15
    No it wont work like that. Man i just cant figure this out!

    - Prilep :(
     
    prilep, Jan 23, 2007 IP
  16. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #16
    OK then final thing : are you sure that the cell name is spelled correctly and it has a value in it ?
     
    maiahost, Jan 23, 2007 IP
  17. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #17
    What do you mean value??

    - Prilep :D
     
    prilep, Jan 23, 2007 IP
  18. MattD

    MattD Peon

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #18
    By value I think he means, is there actually something in it?

    Like if I stored "http://www.mysite.com/avatar.jpg", that would be the value in the field.

    To me it looks like you dont actually have a URL stored in that field of the DB, hence you are getting an empty string back.

    Can you look at the database using something like phpmyadmin to see if there is actually anything there?
     
    MattD, Jan 23, 2007 IP
  19. prilep

    prilep Well-Known Member Premium Member

    Messages:
    3,853
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #19
    Yep there is. I just need it to show. I checked in PHPmyadmin and everything is inserted, but its just not showing :(...

    - Prilep :(
     
    prilep, Jan 23, 2007 IP
  20. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #20
    That just cannot be ... fix the table to make sure there's nothing wrong with it (repair). That's the best I can do ... an avatar field can't just be blank with no reason at all.
     
    maiahost, Jan 23, 2007 IP