EMP |T_IN |T_OUT |ITEM |NOTES
-----------------------------------------
Name 1 | time | time | break | job1
Name 2 | time | time | break | job2
Name 1 | time | time | office |
Name 3 | time | time | fab | job6
上面我需要每行列交集中的每个项目以可编辑的html文本框形式显示,以便提交到下一步。我尝试了几件事......我放弃了所有这些。
<!DOCTYPE html>
<html>
<body>
<form action="test.php" method="post">
Pay Range
<input type="date" name="start">
<input type="date" name="stop">
<input type="submit">
</form>
</body>
</html>
<?php
if($_POST){
mysql_connect('localhost', 'user', 'Pass');
mysql_select_db('database');
$rt = mysql_query("SELECT * FROM TIME WHERE STAMP BETWEEN '". $_POST['start']."' AND '".$_POST['stop']."'");
while($data = mysql_fetch_array($rt)){
$results .= $data['EMP'].", ".$data['T_IN'].", ".$_POST['T_OUT'].", ".$_POST['ITEM'].", ".$_POST['NOTE'];
echo $results."<br/>";
}
}
?>
更新代码:
<!DOCTYPE html>
<html>
<body>
<form action="test.php" method="post">
Pay Range
<input type="date" name="start">
<input type="date" name="stop">
<input type="submit">
</form>
</body>
</html>
<?php
$servername = "localhost";
$username = "user";
$password = "Pass";
$dbname = "DB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM TIME WHERE STAMP BETWEEN '". $_POST['start']."' AND '".$_POST['stop']."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()){
echo "<input type="text" value=\"" . $row['EMP']. "\"> <br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
答案 0 :(得分:1)
这将输出MySql查询中的所有数据
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);?>
<form action="test.php" method="post">
<?php if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()){
echo '<input type="text" name="myinput" value="' . $row["id"]. '"> <br>'
}
} else {
echo "0 results";
}
$conn->close();
?>
</form>
Snippet&amp;有关w3schools
的更多信息