Mysql_fetch_array echo only 1 result

Discussion in 'PHP' started by meannn, Mar 12, 2010.

  1. #1
    Hello, my function echo only 1 result. I want to echo more results with using this function. Can you please help me, thanks!

    function data_dump($query) {
    
    $nt=mysql_query($query);
    echo mysql_error();
    
    $results = array();
    
    while($row=@mysql_fetch_array($nt))
        $results[] = $row;
    
    foreach($results as $key=>$val)
    
    $sitelink = "<h3><a href='http://www.site.com/$val[id]-$val[alt_name].html'>$val[title]</a></strong></h3>$val[short_story]<br>";
    
    echo $sitelink;
    
    return $sitelink;
    
    }
    
    data_dump($query);
    PHP:
     
    meannn, Mar 12, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    Your echo is outside the foreach loop. Try foreach {...;echo ...;}
    Regards :)
     
    koko5, Mar 12, 2010 IP
  3. meannn

    meannn Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Haha lol, I can't believe I did this simple mistake :)

    Большое спасибо
     
    meannn, Mar 12, 2010 IP
  4. skywebsol

    skywebsol Well-Known Member

    Messages:
    161
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    try this one, this will work for you.
     
    skywebsol, Mar 12, 2010 IP