note 99100 added to control-structures.alternative-syntax
| From: | awls99 at gmail dot com | Date: | Tue, 27 Jul 2010 15:19:53 +0000 |
| Subject: | note 99100 added to control-structures.alternative-syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171174@lists.php.net to get a copy of this message | ||
ej at iconcept dot fo made a small mistake, the correct usage for this alternative syntax is:
<?php
$hour = 11;
print $foo = ($hour < 12 ? "Good morning!" : "Good afternoon!");
?>
the diference is the position of the ")"
this syntax is very usefull for SQL queries where you may or may not have user input, like selecting
date from a data base full range or limited by date if the user wants to, as in:
<?php
$SQL = 'SELECT * FROM TABLE where ad = "'.$_GET['graph'].'"
'
.($_GET['min_date'] ? ' and
date>="'.$_GET['min_date'].'"' : '')
.($_GET['max_date'] ? ' and
date<="'.$_GET['min_date'].'"' : '')
.' order by date ASC;'; ?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.193.135.6
----
Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php
Edit -- https://master.php.net/note/edit/99100
Del: integrated -- https://master.php.net/note/delete/99100/integrated
Del: useless -- https://master.php.net/note/delete/99100/useless
Del: bad code -- https://master.php.net/note/delete/99100/bad+code
Del: spam -- https://master.php.net/note/delete/99100/spam
Del: non-english -- https://master.php.net/note/delete/99100/non-english
Del: in docs -- https://master.php.net/note/delete/99100/in+docs
Del: other reasons-- https://master.php.net/note/delete/99100
Reject -- https://master.php.net/note/reject/99100
Search -- https://master.php.net/manage/user-notes.php