While Question

Discussion in 'PHP' started by meannn, Jan 14, 2010.

  1. #1
    Hello, my script is using while to get mysql search results. Here is that part:

    while($row=@mysql_fetch_array($nt)){
    
    $results = $row['title'];
    
    echo $results;
    
    }
    PHP:
    I want to give a value for results, and than echo it. I mean, I dont want to echo this in while section. Anyway to do this?
    Thanks...
     
    meannn, Jan 14, 2010 IP
  2. Steve136

    Steve136 Peon

    Messages:
    240
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could always save it in an array for later use.

    
    $results = array();
    while($row=@mysql_fetch_array($nt)){
        $results[] = $row;
    }
    
    PHP:
    $result is now a multidimensional array, you can access the data by using $results[0]['title'] to get the first row in the table, or loop through it again where you need it...

    
    foreach($results as $key=>$val) {
       echo $val['title']; //Print all found titles.
    }
    
    PHP:
    Regards,
    Steve
     
    Steve136, Jan 14, 2010 IP