0

您好,您能帮我解决一个我遇到问题的脚本吗?\ 我想从不同的列和价格范围创建一个搜索脚本:所以 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();

?> 

填写 $search 和 $pricemin / $pricemax 字段的“ <form method=?>”表单应该是什么?

4

2 回答 2

0

您可以在标签中使用其中一个GETPOST方法<form>

在您的 PHP 脚本中,您可以使用它$form_var_name = $_REQUEST['form_var_name']来访问由表单发送的数据。具体如下

$search = $_REQUEST['search']; 
$pricemin = $_REQUEST['pricemin'];
$pricemax = $_REQUEST['pricemax'];
于 2013-02-16T13:02:19.343 回答
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";
于 2013-02-16T14:22:12.193 回答