TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-11-2009, 02:19 PM   #1 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default 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?
nefus is offline  
Reply With Quote
Old 03-11-2009, 03:53 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

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
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
nefus (03-11-2009)
Old 03-11-2009, 03:58 PM   #3 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

Oh.. ha ha. Quite easy. Thanks!
nefus is offline  
Reply With Quote
Old 03-11-2009, 04:29 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

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.
tony is offline  
Reply With Quote
Old 03-19-2009, 07:12 PM   #5 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default 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?
nefus is offline  
Reply With Quote
Old 03-19-2009, 07:25 PM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by nefus View Post
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.
allworknoplay is offline  
Reply With Quote
The Following User Says Thank You to allworknoplay For This Useful Post:
nefus (03-19-2009)
Old 03-19-2009, 07:27 PM   #7 (permalink)
The Contributor
 
nefus's Avatar
 
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
nefus is on a distinguished road
Default

Ah! Thats peachy. Thanks!
__________________
I am not a programmer, nor do I play one on tv.
nefus is offline  
Reply With Quote
Old 03-19-2009, 10:38 PM   #8 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Please note the @ symbol is very slow and should not be depended above. One shouldn't have errors on a development server showing anyways.
Enfernikus is offline  
Reply With Quote
Old 03-20-2009, 10:46 AM   #9 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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.
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT statement -- list of fields in WHERE clause Dave MySQL & Databases 7 09-17-2008 11:36 AM
Ugh, Query in a while statement Aaron Absolute Beginners 2 08-11-2008 06:36 PM
sql statement help sarmenhb Absolute Beginners 3 06-13-2008 05:00 AM
mysql update statement sarmenhb Absolute Beginners 12 05-20-2008 01:46 AM
User defined function with 'return' statement -- not working Dave Absolute Beginners 3 04-15-2008 07:15 PM


All times are GMT. The time now is 12:29 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design