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 4 7675
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
you could create an alias,
COUNT(*) AS 'number_of_countings'
and later call it as $query['number_of_countings']
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 - ju****@koivi.com http://koivi.com
frizzle wrote: 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
you could create an alias, COUNT(*) AS 'number_of_countings'
and later call it as $query['number_of_countings']
heh - I missed this thread in here, but picked up on it in a.c.d.mysql...
--
Justin Koivisto, ZCE - ju****@koivi.com http://koivi.com
"Justin Koivisto" <ju****@koivi.com> schreef in bericht
news:dL********************@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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: W i l l |
last post by:
I have Apache 2 parsing and serving PHP files just fine on my winXP
box, however, when I try to add some mysql database functionality I
get a warning that looks like this:
Fatal error: Call to...
|
by: Nik Coughin |
last post by:
Today is the first time I've used MySQL with PHP.
What is the best way to turn a column into an array?
This is how I am doing it at the moment, surely this is sub-optimal:
$query = 'SELECT...
|
by: Phil Powell |
last post by:
The table already has a fulltext index and from there I can use the
MySQL fulltext search query to get results as well as the relevancy
score.
The problem I have is that MySQL has a default...
|
by: Börni |
last post by:
Hi,
I have an sql query like this:
SELECT column FROM table WHERE column1="3" AND column2="1"
This query works perfectly if i run it in the command line, to be
exactly it return two results.
But...
|
by: auron |
last post by:
Hi there,
I have a really stupid and banal problem with showing the results of a
MySQL query in PHP, preciselly with MySQL count() function that gives
to a variable in PHP the result.
NOTE:...
|
by: Duderino82 |
last post by:
I was wondering if there is a way to collect the names of the fields
from a specific table. I think the soluction is to be researched in the
sql code but maybe someone knows of a way to o so...
|
by: frizzle |
last post by:
Hi there!
I'd like to create a function which input is the result of a mySQL
query.
The output should be exactly the same, only not a mySQL result array,
but a 'real' array.
So it should also...
|
by: gcox |
last post by:
Hello,
I am using php and MySQL and have following as part of the code
while ($row = mysql_fetch_array($result)) {
printf("<td valign='top'><strong>Venue</strong></td><td _
valign='top'>%s...
|
by: bruno_guedesav |
last post by:
I've made a function to fetch all results as an array of result-
arrays. Getting the result arrays is easy, via mysql_fetch_array, and
function itself is quite simple, as follows:
function...
|
by: ist |
last post by:
Hi,
I am trying to get (and transfer over ASP.NET) some encrypted data
from some MySQL fields. Since the data contains many unicode
characters, I tried to get the data as a series of ASCII...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |