<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
ini_set('display_errors','on');
error_reporting(E_PARSE);
$status=$_POST['status'];
$from=date('y-m-d',strtotime($_POST['date_from']));
$to=date('y-m-d',strtotime($_POST['date_to']));
$conn=mysqli_connect('localhost','root','','punbus') or
die("Database not connected".mysqli_error());
if(isset($_POST['sub'])){
$ins="insert into driver_status(driver_name,status,date_from,date_to)
select Driver_name,'$status','$from','$to' from driver_master";
if(mysqli_query($conn,$ins)){
echo "added";
}
else{
echo "NOT".mysqli_error($conn);
}
}
$sel='select Driver_name from driver_master';
$query=mysqli_query($conn,$sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
echo "<tr>";
echo "<td>".$row['Driver_name']."</td>";
echo "<td>".'<select name="status">';
while($row1=mysqli_fetch_assoc($query1)){
$st=$row1['d_status'];
echo "<option value='$st'>$st</option>";
}
echo "</select></td>";
echo "</tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
</body>
</html>
我想使用计数器因为我想要使$ _POST [status]可重复。所以任何人都可以告诉我如何做到这一点。任何帮助都会得到满足。我想这样做,因为当我从下拉列表中选择值时,它总是为所有下拉框保存相同的值,即从最后一个下拉框中选择。
答案 0 :(得分:0)
一次性完成所有事情?
select dm.Driver_name, s.d_status
from driver_master AS dm
JOIN status AS s;