您好我可以帮助我解决我遇到问题的脚本; \我想从不同的列和价格范围创建一个搜索脚本:所以search.php就是:
<?php
/* connect to the database*/
$db = new mysqli("localhost", "root", "", "movie");
/* check connection */
if ($db->connect_errno) {
echo "Connection failed: " . $db->connect_error;
exit();
}
$query="SELECT * FROM `filmi`
WHERE (`nomer` rlike '%$search%' OR
`rezume` rlike '%$search%' OR
`kategoriq` rlike '%$search%') AND
`seriq` BETWEEN '%$pricemin%' AND '$pricemax'
ORDER BY seriq ASC";
/* create a prepared statement */
if ($stmt = $db->prepare($query)) {
/* bind parameters for markers */
$stmt->bind_param("sssdd", $search, $search, $search, $pricemin, $pricemax);
/* execute query */
$stmt->execute();
/* get result */
$result = $stmt->get_result();
if ($result) {
/* now you can fetch the results into an assoc array */
while ($row = $result->fetch_assoc()) {
echo $row['nomer']. ", " .$row['rezume']. ", " .$row['kategoriq']. ", " .$row['seriq']. "<br>";
}
}
/* close statement */
$stmt->close();
}
/* close db connection */
$db->close();
?>
“<form method=?>
”表单填写$ search和$ pricemin / $ pricemax字段应该是什么?
答案 0 :(得分:0)
您可以在GET
标记中使用POST
或<form>
方法
和
在PHP脚本中,您可以使用$form_var_name = $_REQUEST['form_var_name']
来访问由表单调度的数据。具体如下
$search = $_REQUEST['search'];
$pricemin = $_REQUEST['pricemin'];
$pricemax = $_REQUEST['pricemax'];
答案 1 :(得分:0)
检查$search
是否存在。意味着,$search
是否有一些价值。
if(isset($search) && $search!=''){
case 1
}
else{
case 2
}
案例1 : 如果$ search中有值,则将其包含在where子句中 下面的查询是一个解释我的想法的例子。
$query="SELECT * FROM `filmi`
WHERE (`nomer` rlike '%$search%' OR
`rezume` rlike '%$search%' OR
`kategoriq` rlike '%$search%') AND
`seriq` BETWEEN '%$pricemin%' AND '$pricemax'
ORDER BY seriq ASC";
案例2: 如果$ search中没有值,则不在where子句中包含它 检查以下查询
$query="SELECT * FROM `filmi`
WHERE `seriq` BETWEEN '%$pricemin%' AND '$pricemax'
ORDER BY seriq ASC";