Re: how to extract fields from associative array into different variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nisse Engström wrote:
> On Tue, 16 Jun 2009 08:50:45 -0400, PJ wrote:
>
>   
>> Ashley Sheridan wrote:
>>     
>>> On Mon, 2009-06-15 at 17:38 -0400, PJ wrote:
>>>   
>>>       
>>>> Then I have to add some loopy thing to assign the values to the
>>>> $variables... a real pita since my variable do not lend themselves too
>>>> well to linear alterations ($varIn, $var2IN, $var3IN... etc... so $i=0
>>>> and $i++ arren't going to be too cooperative here... I guess I'd have to
>>>> change that to $var1IN... and then figure out how to do $var.$i.IN ... I
>>>> already tried, but don't seem to have it right
>>>>     
>>>>         
>>> Why do you need them in separate variables? Can't you use them using
>>> array syntax elsewhere in your code?
>>>       
>
>   
>> Basically, I don't know how else to handle inserting and updating random
>> ...
>>     
>
> What he's talking about is doing this:
>
>   if ($res = mysql_query ($sql, $db)) {
>     /* I personally prefer "res" for "resource", not "results" */
>     while ($r = mysql_fetch_assoc ($res)) {
>       $rows[] = $r;
>     }
>   }
>
> And then you access the individual rows/columns as
>   $rows[0]['first_name']
>   $rows[0]['last_name']
>   $rows[1]['first_name']
>   $rows[1]['last_name']
> and so on, in some kind of loop probably.
>
> (I thought this had been spelled out already, but I
>  was unable to find it so perhaps not.)
>
>
> /Nisse
>
>   
Right. I finally got it.
PJ

-- 
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux