[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
[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
[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
> 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
[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
> $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.
>
>
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
[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
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
; $count = mysql_result($result,0);
>
> ---John Holmes...
>
> > - Original Message -
> > From: "DonPro" <[EMAIL PROTECTED]>
> > To: "php list" <[EMAIL PROTECTED]>
> > Sent: Wednesday, October 02, 2002 2:35 PM
> > Subject:
$result,0);
---John Holmes...
> - 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 = 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 M
Hi,
I need to do either an insert or update into a MySQL table. Insert if there
are 0 records or update if one record exist:
This is my code snippet:
if (mysql_query("SELECT COUNT(*) FROM AuthNum") == 0) {
mysql_query("INSERT into AuthNum (FirstNum, LastNum, NextNum) VALUES
(1,2,3)",$dblink
13 matches
Mail list logo