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 e

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 dep

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, bu

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

2002-10-03 Thread 1LT John W. Holmes
> I was thinking along the lines that there needed to be a query that returned > some results that may also be displayed or used within the script. For > instance, I use a paging script that queries for certain conditions and > returns 40 records per page. I also display a line that says, "There a

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 th

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 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 r

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-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['fo

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(); >

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

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