[PHP] Re: Passing by conditional IF statement...why?

2004-03-22 Thread Ligaya Turmelle
I think it is because the query ran successfully and returns an empty set.
So the pointer is still good.

Respectfully,
Ligaya Turmelle


Ryan A [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,
 I have this simple code in my php script:

 * * * * *
 $res = mysql_query(SELECT product_id, now()-1 FROM .$tc._prods where
 cno=$cno AND product_id='$product_id' LIMIT 1);

 if($res)
  {
  $r = mysql_fetch_row($res);
  $product_id2   = $r[0];
  $th_pres= $r[1];
 echo debug echo;
  }else {echo No results, sorry;}
 * * * * *

 its working great when the data actually exists but when there are no
 matches it still executes the if($res) part instead of
 displaying No results, sorry.
 Why is that? or am I using the syntax wrong?

 Thanks,
 -Ryan

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



Re: [PHP] Re: Passing by conditional IF statement...why?

2004-03-22 Thread Daniel Guerrier
if(mysql_num_rows($res))

returns count of rows returned.
if it 0 is false so it shouldn't execute the
conditional code
--- Ligaya Turmelle [EMAIL PROTECTED] wrote:
 I think it is because the query ran successfully and
 returns an empty set.
 So the pointer is still good.
 
 Respectfully,
 Ligaya Turmelle
 
 
 Ryan A [EMAIL PROTECTED] wrote in message

news:[EMAIL PROTECTED]
  Hi,
  I have this simple code in my php script:
 
  * * * * *
  $res = mysql_query(SELECT product_id, now()-1
 FROM .$tc._prods where
  cno=$cno AND product_id='$product_id' LIMIT 1);
 
  if($res)
   {
   $r = mysql_fetch_row($res);
   $product_id2   = $r[0];
   $th_pres= $r[1];
  echo debug echo;
   }else {echo No results, sorry;}
  * * * * *
 
  its working great when the data actually exists
 but when there are no
  matches it still executes the if($res) part
 instead of
  displaying No results, sorry.
  Why is that? or am I using the syntax wrong?
 
  Thanks,
  -Ryan
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html

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



Re: [PHP] Re: Passing by conditional IF statement...why?

2004-03-22 Thread Ryan A
 Ryan A [EMAIL PROTECTED] wrote in message

news:[EMAIL PROTECTED]
  Hi,
  I have this simple code in my php script:
 
  * * * * *
  $res = mysql_query(SELECT product_id, now()-1
 FROM .$tc._prods where
  cno=$cno AND product_id='$product_id' LIMIT 1);
 
  if($res)
   {
   $r = mysql_fetch_row($res);
   $product_id2   = $r[0];
   $th_pres= $r[1];
  echo debug echo;
   }else {echo No results, sorry;}
  * * * * *
 
  its working great when the data actually exists
 but when there are no
  matches it still executes the if($res) part
 instead of
  displaying No results, sorry.
  Why is that? or am I using the syntax wrong?
 
  Thanks,
  -Ryan

Thanks guys,
I'm now using:

if(($r = mysql_fetch_row($res)) =1)

and its working fine, if the above approach has some problems, feel free to
write and tell me.

Cheers,
-Ryan

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



Re: [PHP] Re: Passing by conditional IF statement...why?

2004-03-22 Thread John W. Holmes
Ryan A wrote:

if(($r = mysql_fetch_row($res)) =1)
if($r = mysql_fetch_row($res))

will work fine if you only have one row being returned. If you have more 
than one that you need to loop through, then:

if($r = mysql_fetch_row($res))
{
  do
  {
  }while($r = mysql_fetch_row($res));
}
Now you have the added efficiency of not having to call mysql_num_rows() 
(if you don't need that value).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Re: Passing by conditional IF statement...why?

2004-03-22 Thread Ryan A
Hey John,
Yep, this is just for one row as I need to know which file before I force a
download.
This is for people selling ebooks, MP3s etc

I usually use a while loop if I need multiple rows returned.

Cheers,
-Ryan

On 3/23/2004 3:07:14 AM, [EMAIL PROTECTED] wrote:
 Ryan A wrote:

  if(($r = mysql_fetch_row($res)) =1)

 if($r = mysql_fetch_row($res))

 will work fine if you only have one row being returned. If you have more
 than one that you need to loop through, then:

 if($r = mysql_fetch_row($res))
 {
 do
 {

 }while($r = mysql_fetch_row($res));
 }

 Now you have the added efficiency of not having to call mysql_num_rows()
 (if you don't need that value).

 --
 ---John Holmes...

 Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

 php|architect: The Magazine for PHP Professionals - www.phparch.com

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