NYCPHP Meetup

NYPHP.org

[nycphp-talk] problem with count function

Mark Armendariz nyphp at enobrev.com
Sat Jun 7 03:17:41 EDT 2003


Instead of the count, you may want to run a mysql_num_rows right after
the query is run, which will return the size of the returned array
regardless of MYSQL_ASSOC, MYSQL_NUM, or  MYSQL_BOTH (fetch_array types)

Excerpt from http://www.php.net/manual/en/function.mysql-num-rows.php
------------
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
-----------

Mark

-----Original Message-----
From: Peter Lehrer [mailto:pl at eskimo.com] 
Sent: Friday, June 06, 2003 11:41 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] problem with count function


thanks
----- Original Message -----
From: "Chris Snyder" <chris at psydeshow.org>
To: "NYPHP Talk" <talk at nyphp.org>
Sent: Friday, June 06, 2003 11:05 PM
Subject: Re: [nycphp-talk] problem with count function


> That's cause mysql_fetch_array creates both indexed (numeric) and 
> associative (column names) keys -- so for every column in your result 
> set there are actually two keys-- do print_r($row) to see this.
>
> Take a look at mysql_fetch_assoc() in the manual, too, it might be 
> what you want.
>
>     chris.
>
> Peter Lehrer wrote:
>
> >I noticed when using count() on an array fetched from a mysql db, it
returns
> >twice the amount of elements in the array.
> >
> >For instance:
> ><?
> >$stmt = "SELECT element1,element2,element3,element4,element5 FROM
$table";
> >$sth = mysql_query($stmt, $dbh);
> >
> >$row = mysql_fetch_array($sth);
> >
> >$Count = count($count);
> >?>
> >
> >$Count will equal 10 instead of 5. Has anyone else noticed this
behaviour?
> >
> >--peter
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
> 
>
>



--- Unsubscribe at http://nyphp.org/list/ ---









More information about the talk mailing list