我从如下查询字符串中获取数据,其中country, state and sub
可能未设置所有 3 个。
有时可能是
http://www.example.com/index.php?country=US&state=california&sub=sanjose
http://www.example.com/index.php?country=US&state=california
http://www.example.com/index.php?country=US
然后我做:
$stmt = $conn->prepare('select username from arraytest where country = :country and state = :state and sub = :sub');
$stmt->bindParam(':country', $_GET['country']);
$stmt->bindParam(':state', $_GET['state']);
$stmt->bindParam(':sub', $_GET['sub'])
$stmt->execute();
while($rows = $stmt->fetch()) {
echo $rows['username'];
echo '<br>';
}
这只有在所有三个都绑定时才有效。如果没有收到任何一个,则不返回任何结果。
即使这三个都没有绑定,是否有可能让它工作?
例子
http://www.example.com/index.php?country=US
将显示结果
select username from arraytest where country = US
http://www.example.com/index.php?country=US&state=california
将显示结果
select username from arraytest where country = US and state = california
http://www.example.com/index.php?country=US&state=california&sub=sanjose
将显示结果
select username from arraytest where country = US and state=california and sub=sanjose