![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| 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 | |||
| Advertisements |
| | #2 | ||
| 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' HTH -- Justin Koivisto, ZCE - justin@koivi.com http://koivi.com | |||
| | #3 | ||
| "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. | |||
| Featured Websites | ||||
|
![]() |
| Tags: array, mysql, result |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Same result with differents handler queries | PEx | Database | 0 | 05-31-2007 8:48 PM |
| MySQL Query Cache Not Working: MySQL 5 / Windows XP | Good Man | Database | 0 | 05-31-2007 8:46 PM |
| Select records from result of drop down selection | C. David Rossen | Database | 3 | 05-31-2007 8:40 PM |
| Featured Websites | ||||
|