我需要从数据库中选择下拉列表(时间间隔),然后我点击了提交按钮,你能帮我吗?
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查询中的所有列?
以下链接中的示例。。我的"项目"http://54.187.150.122/php/index3.php
您没有为选择元素指定名称,因此无法发布值。像这样使用:
<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>
正如@Tom Regner所说,mysqli已被弃用,请使用mysql或PDO
这是代码。。谢谢你的帮助!它是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>";
}
?>