Dynamic Queries
| From: | Jamie Jackson | Date: | Mon, 27 Nov 2000 23:18:07 +0000 |
| Subject: | Dynamic Queries | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-27493@lists.php.net to get a copy of this message | ||
Hello,
Newbie question. What's the best, most elegant way to write dynamic
queries? Keep in mind my background is in ColdFusion (and I'm using
PHP3 and MySQL).
Obviously, this is NOT the way to do it, but it'll give you an idea of
what I'm up to:
$str_sql = "
select *
from pers_list2
WHERE
if (isset($fname)) {
fname = '$fname'
}
if (isset($fname) && isset($lname)) {
AND
}
if (isset($lname)) {
lname = '$lname'
}
order by lname
";
Thanks very much,
Jamie