RE: [PHP] Is While needed in MySQL Result with a Limit of 1

2002-04-11 Thread Tim Ward

Why not just use an if instead of a while? This way you test for a result
and get it at the same time

If ($array = mysql_fetch_array($result))
{   foreach($array as $key=?$value) echo("$key=?$value");
} else echo("sorry didn't get anything");

Tim Ward
Internet Chess www.chessish.com <http://www.chessish.com> 

--
From:  Alexander Skwar [SMTP:[EMAIL PROTECTED]]
Sent:  10 April 2002 16:50
To:  Php-General@Lists. Php. Net
    Subject:  Re: [PHP] Is While needed in MySQL Result with a Limit of
1

»Brian Drexler« sagte am 2002-04-10 um 07:58:59 -0400 :
> My question is thisis the while statement needed when I'm only
returning
> one record?

No, it's not.  Since you know that you'll either get 0 or 1 row, you
don't need the while loop.  Instead I'd call mysql_num_rows to see
if
there was 1 row.

Alexander Skwar
-- 
How to quote:   http://learn.to/quote (german) http://quote.6x.to
(english)
Homepage:   http://www.iso-top.de  | Jabber:
[EMAIL PROTECTED]
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
   Uptime: 21 hours 45 minutes

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




Re: [PHP] Is While needed in MySQL Result with a Limit of 1

2002-04-10 Thread Alexander Skwar

»Brian Drexler« sagte am 2002-04-10 um 07:58:59 -0400 :
> My question is thisis the while statement needed when I'm only returning
> one record?

No, it's not.  Since you know that you'll either get 0 or 1 row, you
don't need the while loop.  Instead I'd call mysql_num_rows to see if
there was 1 row.

Alexander Skwar
-- 
How to quote:   http://learn.to/quote (german) http://quote.6x.to (english)
Homepage:   http://www.iso-top.de  | Jabber: [EMAIL PROTECTED]
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
   Uptime: 21 hours 45 minutes

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




Re: [PHP] Is While needed in MySQL Result with a Limit of 1

2002-04-10 Thread Luke van Blerk

No its not.

mysql_fetch_array will return an array if a record is found or false if not.

Regards
Luke

- Original Message -
From: "Brian Drexler" <[EMAIL PROTECTED]>
To: "Php-General@Lists. Php. Net" <[EMAIL PROTECTED]>
Sent: Wednesday, April 10, 2002 1:58 PM
Subject: [PHP] Is While needed in MySQL Result with a Limit of 1


> Here is my code:
>
> mysql_connect("localhost","username","password");
> $result=mysql_db_query("Database","select * from table_name where
> criteria=whatever limit 1");
> while($r=mysql_fetch_array($result) {
> $Value1=$r["TableFieldName1"];
> $Value2=$r["TableFieldName2"];
> echo "$Value1, $Value2";
> }
>
> My question is thisis the while statement needed when I'm only
returning
> one record?
>
> Brian
>
>
> --
> 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] Is While needed in MySQL Result with a Limit of 1

2002-04-10 Thread Brian Drexler

Here is my code:

mysql_connect("localhost","username","password");
$result=mysql_db_query("Database","select * from table_name where
criteria=whatever limit 1");
while($r=mysql_fetch_array($result) {
$Value1=$r["TableFieldName1"];
$Value2=$r["TableFieldName2"];
echo "$Value1, $Value2";
}

My question is thisis the while statement needed when I'm only returning
one record?

Brian


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