2015-11-06 19 views
-1

我需要從我的數據庫(時間間隔)中選擇下拉列表,並且我填寫了提交按鈕,你能幫助我嗎?從我的數據庫中選擇下拉間隔時間-php,sql,

的index.php

<?php 
    mysql_connect("localhost", "user", "pass") or die("Connection Failed"); 
    mysql_select_db("db")or die("Connection Failed"); 
    $query = "SELECT * FROM tbl"; 
    $result = mysql_query($query); 
    $result1= mysql_query($query); 

?> 

<form action="" method="post"> 
    <select> 
     <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>  
      <option value="<?php echo $line['register_date'];?>"><?php echo $line['register_date'];?></option> 
     <?php } ?> 
    </select> 
    <select> 
     <?php while ($line2 = mysql_fetch_array($result1, MYSQL_ASSOC)) { ?> 
      <option value="<?php echo $line2['register_date'];?>"><?php echo $line2['register_date'];?></option><?php } ?> 
    </select> 
    <input type="submit" value="get graph"> 
</form> 

<?php 
    $sql_graph="select * from tbl where register_date>='$line' and register_date<='line2'"; 
    $ress=mysql_query($sql_graph); 
?> 

我的表結構將是:

mysql> select * from table_name; 
+-----+-------+-----------+---------+---------------+ 
| id | hours | item1  | item2 | register_date | 
+-----+-------+-----------+---------+---------------+ 
| 44 | 23:55 | 511657 | 565553 | 2015-09-30 | 
| 48 | 01:55 | 444657 | 144553 | 2015-10-01 | 
| 49 | 02:55 | 2214657 | 144553 | 2015-10-01 | 
| 50 | 03:55 | 1114657 | 224553 | 2015-10-01 | 
| 51 | 04:55 | 414657 | 24553 | 2015-10-01 | 
| 52 | 04:58 | 414655437 | 2453253 | 2015-10-01 | 
| 53 | 04:59 | 55437  | 24553 | 2015-10-01 | 

你能幫助我嗎?


如果我想從列'register_date'中選擇間隔。

2015-09-30 => 2015-10-01並輸出sql查詢中的所有列?

舉例下列link..my「項目」 http://54.187.150.122/php/index3.php

+0

所有'mysql_'函數都被棄用,使用'mysqli'或'PDO :: MySQL'。你的問題到底是什麼? '堅持提交'不是很明確。 –

回答

0

,所以你不能將能夠張貼值你還沒有爲你的選擇元素分配名稱。使用這樣的:

<form action="" method="post"> 
    <select name="register1"> 
     <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>  
      <option value="<?php echo $line['register_date'];?>"><?php echo $line['register_date'];?></option> 
     <?php } ?> 
    </select> 
    <select name="register2"> 
     <?php while ($line2 = mysql_fetch_array($result1, MYSQL_ASSOC)) { ?> 
      <option value="<?php echo $line2['register_date'];?>"><?php echo $line2['register_date'];?></option><?php } ?> 
    </select> 
    <input type="submit" value="get graph"> 
</form> 

正如@湯姆Regner說,mysqli的已過時,使用mysli或原產地名稱

+0

只是響應的一個小擴展: 您的查詢不起作用。 您應該檢查$ _POST是否過濾後變量,然後在查詢中使用後值 – Bolovsky

+0

我該怎麼做? –

0

這裏是代碼..感謝您的幫助!它是100%功能!

<?php 

$con=mysql_connect("localhost", "user_sql", "pass_sql"); 
$db_select= mysql_select_db('db_name', $con); 
$query="select * from tbl_name"; 
if (!$con){ 
die('error: ' . mysql_error()); 
} 
$result = mysql_query($query, $con); 
$result1= mysql_query($query, $con); 
?> 
<form action="script.php" method="POST"> 
<select name="register"> 
<?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> 
<option value="<?php echo $line['id'];?>"><?php echo $line['id'];?></option> 
<?php } ?> 
</select> 
<select name="register1"> 
<?php while ($line2 = mysql_fetch_array($result1, MYSQL_ASSOC)) { ?> 
<option value="<?php echo $line2['id'];?>"><?php echo $line2['id'];?></option><?php } ?> 
</select> 

<input type="submit" name="submit"> 
</form> 

<?php 
if (isset($_POST['submit'])){ 

$query_graph="select * from tbl_name where id>='".$_POST['register']."' and id<='".$_POST['register1']."' "; 
$result2= mysql_query($query_graph, $con); 

echo "<table>"; 
     while ($row = mysql_fetch_array($result2)){ 
       echo "<tr><td>". $row['id'] ."</td>"; 
       echo "<td>". $row['hours'] ."</td>"; 
       echo "<td>". $row['node1'] ."</td>"; 
       echo "<td>". $row['node2'] ."</td>"; 
       echo "<td>". $row['register_date'] ."</td></tr>"; 
} 

echo "</table>"; 
} 
?> 
相關問題