开发者

automatic mysql query in PHP

How do i write a code that builds a mysql query depending on what values drop lists have?

If nothing is chosen in a drop list, then the drop list value is 001 so then the query should not include this drop list in the search!

Please help...

I have this so far:

            foreach($_GET as $key => $value) {
    if ($value != '001') {
                 Do something smart.开发者_StackOverflow社区..like add to a query...
                     }
        }


Send the form to a PHP file called (say) script.php with method GET (or POST, if you prefer - in which case replace the references to GET below):

In script.php include the following:

<?php
if (!isset($_GET['yourdroplistname']) {
  $value = 001;
} else {
  $value = mysql_real_escape_string($_GET['yourdroplistname']);
}
mysql_query("YOUR QUERY, CONTAINING $value WHERE APPROPRIATE");
?>


I recommend to use a switch($droplist) to filter what PHP should do.

switch($droplist)
case '1':
$query = 'SELECT 1 FROM xy WHERE userid = 1';
break;
case '2':
// etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜