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! Quote 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 Quote 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? Quote 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 == " ") Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/164368-php-hacks/#findComment-867693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.