0

我需要对该表进行排序以显示使用文本框设置的 2 个值之间的价格,但我尝试了很多验证,但它在这里不起作用是文本框的形式和我认为查询应该是什么(来自 index2.php ):

<form action ="index2.php" method="post">
                        Games priced<input action="index2.php" method="post" type="text" name="min">
                        Between<input action="index2.php" method="post" type="text" name="max">
                        <input type="submit" value="Sort">

                        <?php

                        $query = "SELECT * FROM CSGames WHERE price <=min AND >=max ";
                        $result = pg_query("SELECT * FROM CSGames WHERE price <=min AND >=max ");

                        ?>

这是我正在使用的 sql 数据库

<?php
$con = pg_connect("bla bla");
    if (!$con)
        {
    die('Could not connect: ' . pg_error());
        }
    $result = pg_query("SELECT * FROM CSGames");
    echo "<table>
    <tr>
    <th>Title</th>
    <th>Platform</th>
    <th>Description</th>
    <th>Price</th>
    <th>Select</th>
    </tr>";

    while($row = pg_fetch_array($result)){
    echo"<tr>";
    echo "<td>" . $row['1'] . "</td>";
    echo "<td>" . $row['2'] . "</td>";
    echo "<td>" . $row['3'] . "</td>";
    echo "<td>" . $row['4'] . "</td>";
    echo '<td><input type="checkbox" name="games[]" value="' . $row['1'] . '|||' . $row['2'] . '|||'. $row['3'] . '|||' . $row['4'] . '"/></td>';

    echo"</tr>";      
        }
    echo"</table>";

pg_close($con);

?>

我认为这只是错误的查询,但我不确定它是否有帮助这是我正在处理的页面 http://users.aber.ac.uk/edd14/cs25010/index.php

4

2 回答 2

2

在这里,一个 between 子句仅适用于这些情况:

SELECT * FROM `CSGames`
WHERE `price` BETWEEN min AND max;

文档:http ://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

将 min 和 max 替换为表单中经过清理的$_POST 变量。

于 2012-11-29T14:15:30.183 回答
1
     $query = "SELECT * FROM CSGames WHERE price >=min AND price <=max ";
     $result = pg_query("SELECT * FROM CSGames WHERE price >=min AND price <=max ");
于 2012-11-29T14:13:34.513 回答