RE: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread Jay Blanchard
[snip] Or another way if you don't want a result when it's zero. $rslt = mysql_query(SELECT count(*) as cnt FROM tbl having cnt 0); [/snip] $result = mysql_query(SELECT * FROM tbl); $number_of_rows = mysql_num_rows($result); You don't have to do the count in the SQL, as John said earlier a

RE: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread Jason D
An alternative way is to add a primary or unique key and make the code snippet like this: mysql_query(INSERT ignore into AuthNum (FirstNum, LastNum, NextNum, KeyField) VALUES (1,2,3,1),$dblink); mysql_query(Update AuthNum Set FirstNum = 1, LastNum = 2, NextNum = 3,$dbLink); If there is a

Re: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread 1LT John W. Holmes
$result = mysql_query(SELECT * FROM tbl); $number_of_rows = mysql_num_rows($result); You don't have to do the count in the SQL, as John said earlier a SELECT COUNT(*) FROM tbl will always return one row, even if the value of the row is 0. Of course you could always test for that.

RE: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread Jay Blanchard
[snip] $result = mysql_query(SELECT * FROM tbl); $number_of_rows = mysql_num_rows($result); You don't have to do the count in the SQL, as John said earlier a SELECT COUNT(*) FROM tbl will always return one row, even if the value of the row is 0. Of course you could always test for that.

RE: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread Jay Blanchard
[snip] I still think it's more effecient to use two queries in your case. One with a COUNT(*) to get total records, and one with a LIMIT to just get the 40 you want. With a smaller table, it may not matter, but with large tables, you could be using up a lot of resources by selecting everything,

RE: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread John W. Holmes
[snip] I agree that COUNT is an optimized return, but for a situation where you are retrieving data from the query for whatever use it is more efficient to use mysql_num_rows() to return the count of this particular query than it would be to issue a second query, no? Yes, it all depends

RE: [PHP] counting number of records in a MySQL table; how do I get

2002-10-03 Thread Jay Blanchard
[snip] I think we're arguing with each other even though we agree on everything. :) [/snip] I prefer to think of it as healthy discussion :^] It is like two quantum physicists discussing light, with one leaning towards the particle side and the other leaning towards the wave side. They agree on

Re: [PHP] counting number of records in a MySQL table; how do I get the result?

2002-10-02 Thread Kevin Stone
$result = mysql_query(); if (mysql_num_rows($result) $x) -Kevin - Original Message - From: DonPro [EMAIL PROTECTED] To: php list [EMAIL PROTECTED] Sent: Wednesday, October 02, 2002 2:35 PM Subject: [PHP] counting number of records in a MySQL table; how do I get the result? Hi, I

RE: [PHP] counting number of records in a MySQL table; how do I get the result?

2002-10-02 Thread John W. Holmes
$result = mysql_query(); if (mysql_num_rows($result) $x) -Kevin This won't work because a SELECT COUNT(*) query always returns a row, even if it returns zero as the value. $result = mysql_query(SELECT COUNT(*) FROM ... ); $count = mysql_result($result,0); ---John Holmes... - Original

Re: [PHP] counting number of records in a MySQL table; how do I get the result?

2002-10-02 Thread Jeff Bluemel
so why not take that resulting row, and then do an if on it to see if the value is a zero? an extra step, but it would work John W. Holmes [EMAIL PROTECTED] wrote in message 002c01c26a66$61f0e1a0$7c02a8c0@coconut">news:002c01c26a66$61f0e1a0$7c02a8c0@coconut... $result = mysql_query(); if

Re: [PHP] counting number of records in a MySQL table; how do I get

2002-10-02 Thread Dan Koken
Or another way if you don't want a result when it's zero. $rslt = mysql_query(SELECT count(*) as cnt FROM tbl having cnt 0); HTH.. Have a great day.. Dan Rasmus Lerdorf wrote: $ret = mysql_query(SELECT count(*) as foo FROM AuthNum); $result = mysql_fetch_array($ret); echo $result['foo'];