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

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

am 26.05.2009 13:01:28 von Jacob Kruger

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...'



--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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

am 26.05.2009 17:00:52 von Jacob Kruger

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"
To: "Jacob Kruger"
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


> Jacob Kruger wrote:
>> 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...'
>>
>>
>>
> 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




--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php