我有这段代码——它试图从 URL 中获取变量,然后根据条件(NULL 值除外)进行 MYSQL 选择。但是,我相信我要去某个地方,但我不知道在哪里:
<?php
include('db.php'); // include your code to connect to DB.
$tbl_name="mobile"; //your table name
$model = ($_GET['model'] ? $_GET['model'] : NULL);
$mins = ($_GET['mins'] ? $_GET['mins'] : NULL);
$texts = ($_GET['texts'] ? $_GET['texts'] : NULL);
$freegift = ($_GET['free-gift'] ? $_GET['free-gift'] : NULL);
$network = ($_GET['network'] ? $_GET['network'] : NULL);
$plan = ($_GET['plan'] ? $_GET['plan'] : NULL);
$vars = array($model, $mins, $texts, $freegift, $network, $plan);
foreach($vars as $value) {
$value = (isset($_GET[$value]) ? $_GET[$value] : NULL);
unset ($vars[$value]); //sweeping the NULL ones
}
$where_clause = $vars[0]; //the only remaining value after previous cleanup
$where = '';
if (count($whereClauses) > 0) {
$where = ' WHERE '.implode(' AND ',$whereClauses);
}
$sql5 = mysql_query("SELECT * FROM $tbl_name".$where);
这根本行不通。它应该像www.domain.com/page.php?mobile=Samsung&mins=500
- 应该使用变量来执行搜索。