Re: HOW do I return the results of a count to a variable
At 11:34 AM +0100 11/1/01, Harald Fuchs wrote: In article p05100345b8063ddb205a@[192.168.1.31], Paul DuBois [EMAIL PROTECTED] writes: [snip] Of all the methods suggested I like the look of the one above and will try that one first. $count = $sth-fetchrow_array(); $rows = $sth-rows() Note that use of rows() to get the row count for a SELECT is deprecated in the DBI docs, which say that if you want to know the number of rows in a result set, fetch and count them. (The reason is that rows() just doesn't work at all for some database engines. On the other hand, it appears to work just fine for MySQL...) ... unless you use 'mysql_use_result' instead of the default 'mysql_store_result'. Another reason to avoid rows(). :-) - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: HOW do I return the results of a count to a variable
[snip] Of all the methods suggested I like the look of the one above and will try that one first. $count = $sth-fetchrow_array(); $rows = $sth-rows() Note that use of rows() to get the row count for a SELECT is deprecated in the DBI docs, which say that if you want to know the number of rows in a result set, fetch and count them. (The reason is that rows() just doesn't work at all for some database engines. On the other hand, it appears to work just fine for MySQL...) $count = $dbh-selectrow_array ( SELECT COUNT(*) FROM go.objectives WHERE subjects_id='1' AND subjectHeadings_id='2'); Thankyou all. -- Home:- hinwickATworsdall.demon.co.ukWEB:- http://www.worsdall.demon.co.uk Shadow:- webmasterATshadow.org.uk WEB:- http://www.shadow.org.uk - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: HOW do I return the results of a count to a variable
Have you tried using the $rows = $sth-rows() after you execute to get the total rows returned? On Wed, 31 Oct 2001 00:43:00 +, Mark Worsdall [EMAIL PROTECTED] wrote: Hi, I want to alter this statement so it returns the number of records. $prep = SELECT COUNT(*) FROM go.objectives WHERE subjects_id='1' AND subjectHeadings_id='2' ORDER BY displayOrder; $sth = $dbh-prepare($prep); $sth-execute; So what I need to do is add the COUNT statement into the above and then return the number of records but how? MySQL table query Mike(mickalo)Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! http://www.thunder-rain.com Tel: 1(225)686-2002 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: HOW do I return the results of a count to a variable
I'm new to this list, and new to mySQL but used SQL with DB2 years ago, so here goes my try at answering this: have you tried select count(*) as your_variable_name From etc .etc.etc. Anne - Original Message - From: Mark Worsdall [EMAIL PROTECTED] To: MySQL [EMAIL PROTECTED] Sent: Tuesday, October 30, 2001 7:43 PM Subject: HOW do I return the results of a count to a variable Hi, I want to alter this statement so it returns the number of records. $prep = SELECT COUNT(*) FROM go.objectives WHERE subjects_id='1' AND subjectHeadings_id='2' ORDER BY displayOrder; $sth = $dbh-prepare($prep); $sth-execute; So what I need to do is add the COUNT statement into the above and then return the number of records but how? MySQL table query M. -- Work:- postmasterAThinwick.demon.co.uk WEB:- http://www.hinwick.demon.co.uk Work:- mworsdallATshaftesburysoc.org.uk REPLACE AT with @ Home:- hinwickATworsdall.demon.co.ukWEB:- http://www.worsdall.demon.co.uk Shadow:- webmasterATshadow.org.uk WEB:- http://www.shadow.org.uk - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php