You are here: Re: Mysql result to array « MySQL Databases « IT news, forums, messages
Re: Mysql result to array

Posted by Jaak on 01/13/06 18:20

"Justin Koivisto" <justin@koivi.com> schreef in bericht
news:dLGdnV0pDpb1jFjeRVn-rg@onvoy.com...
> Jaak wrote:
>> I have this query, it gives the suspected information in myphpadmin:
>>
>> select listid, count(*) from table1 group by listid
>>
>> How do I put this the result into an array in php? I have problems with
>> the
>> count(*) field
>>
>>
>
> $q='select listid, count(*) from table1 group by listid';
> $res=mysql_query($q);
> if($res){
> $data=array();
> while($row=mysql_fetch_array($res,MYSQL_NUM)){
> $data[]=array(
> 'listid' => $row[0],
> 'count' => $row[1]
> );
> }
> }
>
> Untested, but it should give you the idea... Another option is to change
> the query to something similar to:
>
> select listid, count(*) as num_found from table1 group by listid
>
> Then if you are using mysql_fetch_assoc, then the key name will be
> 'num_found'
Thanks Justin, it really helped me! I was confused with the 'count' thing,
because this was not really a field in the table.

 

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

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