Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Counting returned MySQL rows, and possibly storing returned recordset in a session variable

1 view
Skip to first unread message

Jacob Kruger

unread,
May 26, 2009, 7:01:28 AM5/26/09
to php-w...@lists.php.net
As far as I know/thought, you could include something like COUNT(*) in a
list of fields to be returned from MySQL to get told how many rows were
returned by mysql_query, but it doesn't seem to want to work on this
instance of MySQL I have here installed inside WAMP.

Also, if I try assigning the result of mysql_query to a session variable,
the mysql_fetch_array function doesn't work since the result set hasn't been
assigned to the current mysql session or something - is there any way to
carry this over page to page without requerying the database itsself?

TIA

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'


Jacob Kruger

unread,
May 26, 2009, 11:00:52 AM5/26/09
to php-w...@lists.php.net
Will look at the mysql_num_rows function.

Suppose I could try something like assigning the whole returned recordset to
an array that I then saved in a session variable, but depending on the size
of the returned data rows it might not be worth it in terms of load on the
server.

Am currently just looping through previously displayed rows and then
displaying the 'current' ones at this stage.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message -----
From: "James Crow" <ja...@ultratans.com>
To: "Jacob Kruger" <jac...@iburst.co.za>
Sent: Tuesday, May 26, 2009 4:47 PM
Subject: Re: [PHP-WIN] Counting returned MySQL rows, and possibly storing
returned recordset in a session variable

> Using count(*) should work. If you just want the number of rows returned
> by a query then use one of the mysql functions for that.
> SELECT & SHOW use mysql_num_rows()
> INSERT, UPDATE, DELETE, & REPLACE use mysql_affected_rows()
>
> I do no think you can carry a mysql_result set from one script to the
> next. At the end of script execution an implicit mysql_close is called.
> That would free any result sets that had not been freed during script
> execution. You could look at mysql_pconnect, but the comments about it
> seems to indicate that it has its own issues.
>
> Cheers,
> James

0 new messages