TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   if statement success (http://www.talkphp.com/absolute-beginners/4033-if-statement-success.html)

nefus 03-11-2009 02:19 PM

if statement success
 
I am pretty sure the following is true:

Code:

$result = mysqli_query( $link , $sql );
if(!$result) { do something if fails}

The ! is used in that instance to run the loop if the sql statement failed. Is there a way to check for success in the same way?

tony 03-11-2009 03:53 PM

you mean to check if the query was a success?
it's the same except for the exclamation point.

PHP Code:

if($result){
    
//do something with the result


oh and P.D. if is a language construct not a loop :P

nefus 03-11-2009 03:58 PM

Oh.. ha ha. Quite easy. Thanks!

tony 03-11-2009 04:29 PM

no problem. it's weird because I learned about this way of comparison the other way around, asking how to compare a false value :P
have fun coding.

nefus 03-19-2009 07:12 PM

hmmm
 
I ran into something today that looks a tiny bit different.

Any real difference between

Code:

if($result){
    //do something with the result
}

and this

Code:

if(@$result){
    //do something with the result
}

Why use the @ symbol?

allworknoplay 03-19-2009 07:25 PM

Quote:

Originally Posted by nefus (Post 22367)
I ran into something today that looks a tiny bit different.

Any real difference between

Code:

if($result){
    //do something with the result
}

and this

Code:

if(@$result){
    //do something with the result
}

Why use the @ symbol?


The @ symbol suppresses warning messages.

nefus 03-19-2009 07:27 PM

Ah! Thats peachy. Thanks!

Enfernikus 03-19-2009 10:38 PM

Please note the @ symbol is very slow and should not be depended above. One shouldn't have errors on a development server showing anyways.

Tanax 03-20-2009 10:46 AM

Instead of using the @ supression symbol, which Enfernikus stated is slow, you should display all errors when you're developing the script.
When the script is going "live", you should then use error_reporting(0) to remove all errormsg.


All times are GMT. The time now is 04:27 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0