oskom Posted December 5, 2007 Share Posted December 5, 2007 Hello all...again, forum helper, rab, was kind enough to provide me with some useful code: <?php $_REQUEST['contentID'] = (int)$_REQUEST['contentID'] < 0 ? 0 : (int)$_REQUEST['contentID']; if( $_REQUEST['contentID'] > 0 ) { $result = mysql_query("SELECT * FROM content WHERE contentID = '{$_REQUEST['contentID']}'"); if(!$result) { // ERROR } } else { // Need an ID } ?> Problem is...I'm not totally clear on what the first line is doing(please forgive the novice smell). In other words, I know what this part is doing... $_REQUEST['contentID'] = (int)$_REQUEST['contentID'] ...but not this part... < 0 ? 0 : (int)$_REQUEST['contentID'] I'm thinking it's some kind of short-form if/else statement, but... Enlightenment? Link to comment https://forums.phpfreaks.com/topic/80200-solved-what-does-this-code-do/ Share on other sites More sharing options...
btherl Posted December 5, 2007 Share Posted December 5, 2007 Yes it's a short and simplified form of if-then-else. You use it where you want to use either one value or another value. For example, if you are generating html for a checkbox that may or may not be checked $checked_text = ($box_is_checked ? " CHECKED " : ""); Or if you want to set a number to 0 if it's less than 0 $num = ($num < 0 ? 0 : $num); Link to comment https://forums.phpfreaks.com/topic/80200-solved-what-does-this-code-do/#findComment-406488 Share on other sites More sharing options...
oskom Posted December 5, 2007 Author Share Posted December 5, 2007 Thanks, btherl! Gotta new tool in my arsenal! Link to comment https://forums.phpfreaks.com/topic/80200-solved-what-does-this-code-do/#findComment-406496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.