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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    310
    Thanks
    86
    Thanked 3 Times in 3 Posts

    Returning values from a while loop into an array?

    Hello,

    I'm after a bit of help if possible with regards to a while loop.

    I have a query, which I return the results of in a while loop and I hold each value in an array.

    PHP Code:
    While($row mysql_fetch_array($result)) {
        
    $search_tags = array();
        
    $search_tags $row['name'];
      } 
    Now what I want to do is take each of these twelve values returned and pass them to another array outside of the while loop. In this array certain numeric values already exist . I've tried this using list, but I get a message saying Variable passed to each() is not an array or object .

    PHP Code:
    While($row mysql_fetch_array($result)) {
        
    $search_tags = array();
        
    $search_tags $row['name'];
      } 
       list (
    $val1$val2$val3$val4$val5$val6$val7$val8$val9$val10$val11$val12) = each($search_tags);  
       
    $tags = array($val1 => 42$val2 => 38$val3 => 32$val4 => 29$val5 => 26$val6 => 24$val7 => 20$val8 => 16$val9 => 12$val10 => 11$val11 => 10$val12 => 8); 
    Can anyone please help?

    Thanks
    Last edited by stfc_boy; 08-08-2011 at 03:22 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    PHP Code:
    While($row mysql_fetch_array($result)) {
        
    $search_tags[] = $row['name'];
      } 
    I think thats what you're looking for with the first bit of code.. second bit I'm lost on but I've only just woken up and the head is still a bit fizzy..
    I can't really think of anything to write here now...

  • Users who have thanked tangoforce for this post:

    stfc_boy (08-08-2011)


  •  

    Posting Permissions

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