note 37585 modified in control-structures.alternative-syntax by vrana
| From: | vrana@php.net | Date: | Thu, 05 Aug 2004 18:11:28 +0000 |
| Subject: | note 37585 modified in control-structures.alternative-syntax by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74046@lists.php.net to get a copy of this message | ||
My personal preference on alternating writing is like this:
<?php
$query="select * from books";
sizeof($myparam) and $query.=" where title like '%$myparam%'";
?>
Which means: if (sizeof($myparam)) $query.= ...
You can even combine this with the ? structure.
Like:
<?php
$query="select * from books";
strlen($title) and $c1=" title like '%$title%'";
strlen($year) and $c2=" year=$year";
strlen($c1) and $q2=$c1;
strlen($c2) and $q2.= (strlen($q2)) ? "and $c2" : $c2;
strlen($q2) and $query.=" where $q2";
?>
Well, how about this? Can it be done easier? :)
I think is is called lazy Vs eager calc.
--was--
My personal preference on alternating writing is like this:
$query="select * from books";
sizeof($myparam) and $query.=" where title like '%$myparam%'";
Which means: if (sizeof($myparam)) $query.= ...
You can even combine this with the ? structure.
Like:
$query="select * from books";
strlen($title) and $c1=" title like '%$title%'";
strlen($year) and $c2=" year=$year";
strlen($c1) and $q2=$c1;
strlen($c2) and $q2.= (strlen($q2)) ? "and $c2" : $c2;
strlen($q2) and $query.=" where $q2";
Well, how about this? Can it be done easier? :)
I think is is called lazy Vs eager calc.
http://php.net/manual/en/control-structures.alternative-syntax.php