Monkuar Posted July 1, 2009 Share Posted July 1, 2009 $orderby = (isset($_GET['@amount'])) ? 'amount' : 'date_time'; I heard using ? and : is a hack and ? stands for a if function ~ and : stands for else? Can u tell me what this is called is there other ways to do this like this? How can I add more to this code too $orderby = (isset($_GET['@amount'])) ? 'amount' : 'date_time' :'id'; like see If I add the : 'id' to it i get a syntax error, unexpected ':', possible ?thanks phpfreaks! Link to comment https://forums.phpfreaks.com/topic/164368-php-hacks/ Share on other sites More sharing options...
Mark Baker Posted July 1, 2009 Share Posted July 1, 2009 It's called a ternary operator. You can find out more about it in the manual Don't know exactly what you're trying to do here $orderby = (isset($_GET['@amount'])) ? 'amount' : 'date_time' :'id'; But when you have two colons, by your own logic, this would equate to: if (isset($_GET['@amount'])) { $orderby = 'amount'; } else { $orderby = 'date_time' } else { $orderby = 'id'; } which isn't valid PHP at all Link to comment https://forums.phpfreaks.com/topic/164368-php-hacks/#findComment-867071 Share on other sites More sharing options...
Monkuar Posted July 1, 2009 Author Share Posted July 1, 2009 It's called a ternary operator. You can find out more about it in the manual Don't know exactly what you're trying to do here $orderby = (isset($_GET['@amount'])) ? 'amount' : 'date_time' :'id'; But when you have two colons, by your own logic, this would equate to: if (isset($_GET['@amount'])) { $orderby = 'amount'; } else { $orderby = 'date_time' } else { $orderby = 'id'; } which isn't valid PHP at all Would i need to put else if in therE? Link to comment https://forums.phpfreaks.com/topic/164368-php-hacks/#findComment-867441 Share on other sites More sharing options...
Monkuar Posted July 2, 2009 Author Share Posted July 2, 2009 //monkuar if($ibforums->input['screen1'] == "") { $std->Error( array( 'LEVEL' => 1, 'MSG' => 'file_screen_empty') ); } I need to make it only .gif and .jpg extensions are allowed, help ? something with == " ") Link to comment https://forums.phpfreaks.com/topic/164368-php-hacks/#findComment-867677 Share on other sites More sharing options...
trq Posted July 2, 2009 Share Posted July 2, 2009 Can you at least try to explain your issue? Your last post doesn't seem at all related to your original question. Link to comment https://forums.phpfreaks.com/topic/164368-php-hacks/#findComment-867693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.