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 (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 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 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);
> > > } else {
> > >mysql_query("Update AuthNum Set FirstNum = 1, LastNum = 2,
> NextNum =
> > > 3",$dbLink);
> > > }
> > >
> > > My problem is, a record never gets inserted because the SELECT COUNT
> > query
> > > is returning a resource ID of 2.  How can I get the actual number of
> > records
> > > in the table?
> > >
> > > Thanks,
> > > Don
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>



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




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 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 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);
> > } else {
> >mysql_query("Update AuthNum Set FirstNum = 1, LastNum = 2,
NextNum =
> > 3",$dbLink);
> > }
> >
> > My problem is, a record never gets inserted because the SELECT COUNT
> query
> > is returning a resource ID of 2.  How can I get the actual number of
> records
> > in the table?
> >
> > Thanks,
> > Don
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php




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




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 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);
> } else {
>mysql_query("Update AuthNum Set FirstNum = 1, LastNum = 2, NextNum =
> 3",$dbLink);
> }
>
> My problem is, a record never gets inserted because the SELECT COUNT query
> is returning a resource ID of 2.  How can I get the actual number of
records
> in the table?
>
> Thanks,
> Don
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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