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 23:18

frizzle wrote:
> Gerard Matthew wrote:
>> Frizzle,
>>
>> mysql_fetch_array() by default returns both result types. MYSQL_ASSOC
>> and MYSQL_NUM
>>
>> Therefore mysql_fetch_array($result, MYSQL_BOTH) is the same as
>> mysql_fetch_array($result) based on the return values.
>>
>> For numeric indicies you use MYSQL_NUM...
>> mysql_fetch_array($result,MYSQL_NUM);
>> and for associative indicies you would use MYSQL_ASSOC...
>> mysql_fetch_array($result,MYSQL_ASSOC).
>>
>> Hope this helps out in understanding.
>>
>> Rgds,
>> Gerard.
>
> Yes it does. Thanks!
>
> @David:
>
> table: FOO
> id login Name Address1
> 1 fred Fred Flinstone 123 Anywhere
> 2 barney Barney Rubble 125 Anywhere
>
> array:
> result[1][login] = fred
> result[2][name] = Barney Rubble
>
> Something like that. But only if 'id' is a returned field,

I'm having trouble with what you mean by this. I am going to assume
that you mean 'when id is not null'.

> else use default array indices.
> (and how could i define the array's name as another
> function var ? )
>
> Anyways, both you guys helped me a lot already!
>
> Frizzle.
>

I take it the database design is not something you can change. sigh!

OK, how about this?

$default = 'login'; // The default column to use if 'id' is not set
while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
if( $row['id'] != '' ) { // id is not null
$return[][$row['id']] = $row[$row['id']];
} else { // id is null
$return[]['default'] = $row[$default];
}
}

-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

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