2012-11-29 14 views
0

我需要對此表進行排序以顯示2個值之間的價格,這些值是使用文本框設置的,但是我嘗試了加載的驗證,但它只是不會工作 這裏是文本框的形式以及我認爲查詢應該是index2.php):PHP - 有人可以幫我做一個SQL排序來獲得2價格值之間的清單嗎?

<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數據庫IM期運用

<?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); 

>

我認爲它只是在查詢那是錯誤的,但林不知道? 10,如果有幫助,這是網頁IM上 http://users.aber.ac.uk/edd14/cs25010/index.php

+0

你可以使用? – johnny

回答

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

它繼續拋出:Warning:pg_query()[function.pg-query]:沒有打開PostgreSQL鏈接在/ceri/homes1/e/edd14/public_html/cs25010/index2.php在線61 – user1861710

+0

這聽起來像你沒有' t建立了與數據庫的連接,並且與查詢無關。 http://php.net/manual/de/function.pg-pconnect.php – lawl0r

+0

對,你知道我會如何開始這一行嗎? – user1861710

2

在這裏你去工作,一個條款只是針對這些情況之間:

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

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

更換的最小值和最大值與您的消毒 $ _POST變量從您的窗體。

+0

它一直在投擲 – user1861710

+0

正在投擲...出錯?哪一個? – phpisuber01

+0

對不起,它的拋出:Warning:pg_query()[function.pg-query]:查詢失敗:錯誤:列「min」不存在LINE 1:SELECT * FROM CSGames WHERE price BETWEEN min AND max; ^在第59行的/ceri/homes1/e/edd14/public_html/cs25010/index2.php – user1861710

相關問題