note 99100 deleted from control-structures.alternative-syntax by danbrown
| From: | danbrown@php.net | Date: | Fri, 30 Jul 2010 16:40:22 +0000 |
| Subject: | note 99100 deleted from control-structures.alternative-syntax by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171262@lists.php.net to get a copy of this message | ||
Note Submitter: awls99 at gmail dot com
----
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;'; ?>