You are here: Re: mySQL result to real array in function « PHP Programming Language « IT news, forums, messages
Re: mySQL result to real array in function

Posted by David Haynes on 04/25/06 22:37

frizzle wrote:
> David Haynes wrote:
>> frizzle wrote:
>>> David Haynes wrote:
>>>> $result[] = causes the result to be pushed onto an indexed array not an
>>>> associative array. See inline for fix.
>>>>
>>>> -david-
>>>>> $get_res = mysql_query(QUERY);
>>>>>
>>>>> if( $res = mysql_fetch_array( $get_res ) )
>>>>> {
>>>>>
>>>>> do{
>>>>>
>>>> $result[$res['field1']] = $res['field1 value'];
>>>>> } while( $res = mysql_fetch_array( $get_res ) );
>>>>>
>>>>> };
>>>>>
>>>>> foreach( $result as $key => $value ){
>>>>>
>>>>> print_r($value);
>>>>>
>>>>> };
>>> David,
>>>
>>> i don't alwas know all fieldnames beforehand.
>>> So SELECT * should also put all fieldnames as
>>> keys in the array.
>>>
>>> Frizzle.
>>>
>> My assumption was that one column in the table being queried formed the
>> keys for the associative array. If so, then my method works. If not,
>> what were you planning on using as the key to the array?
>>
>> -david-
>
> Having read it again and again i get it.
> ideally, it would check if there is an 'id' in the returned fields and
> use that
> as index ...
>
> Frizzle.
>

Can you provide a sample of the table you are querying? It doesn't have
to contain real data but should include the column names and an example
of the array result you would like. It's easier to provide you with help
if the example is close to the problem.

Something like:
FOO
login Name Address1
fred Fred Flinstone 123 Anywhere
barney Barney Rubble 125 Anywhere

array:
result['fred'] = ...
result['barney'] = ...

-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация