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 3 of 3
  1. #1
    FUN
    FUN is offline
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy mysql_fetch_array in a function

    I'm stuck, i made a function that gets the news from the database, and it is supposed to get 4 last rows of the database, and then after i print it is suppose to output 4 last results, but it doesn't it ouputs only one...

    PHP Code:
    function news(){
                    
    $newsdb="SELECT*FROM news order by id";
                    
    $getnews=mysql_query($newsdb) or die(mysql_error());
                    while(
    $r=mysql_fetch_array($getnews)){
                    
    $id=$r[id];
                    
    $title=$r[title];
                    
    $body=$r[body];
                    
    $writter=$r[username];
                    
    $time=$r[time];
                    
    $newsboard="$title <br /> $body <br />$writter <br /> \n $time <br /> \n<a href=\"$self?nid=$id\">comments</a><br />";
                    }
                    return 
    $newsboard;
                    } 
    and they i print it
    PHP Code:
    <?php 
    print news();
    ?>

    Can u tell me where is the mistake...

    It seems that it returns the first thing that it gets in $newsboard var... but how to make so it takes all the rows ???

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    $newsboard .= "etc, note the '.' (dot)";
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    FUN
    FUN is offline
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow, thanks firepages, your help was brilliant and simple!
    i've tried everything but i had to put only 1 dot, brilliant, lol,

    Me stupid


  •  

    Posting Permissions

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