我希望在按特定数组执行循环时将值发布到一行,但是当点击底部然后将其发布在"响应"所有表格数组中的行!!
<?php
require_once('config.php');
$con->set_charset('utf8');
$query = "select * from contact order by id";
$result = mysqli_query($con,$query);
while($name = mysqli_fetch_array($result)){
echo '<table width="200" border="1" align="right">';
echo "<tr>";
echo "<td align='center'> <div align='center'> <b> $name[id] </b> </td>";
echo "<td align='center'> <div align='center'> <b> The number </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <div align='center'> <b> $name[ticketnumber] </b> </td>";
echo "<td align='center'> <div align='center'> <b> ticket number </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[name] </b> </td>";
echo "<td align='center'> <b> name </b> </div> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[phone] </b> </td>";
echo "<td align='center'> <b> phone </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[email] </b> </td>";
echo "<td align='center'> <b> email </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[subject] </b> </td>";
echo "<td align='center'> <b> subject </b> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'> <b> $name[response] </b> </td>";
echo "<td align='center'> <b> response </b> </td>";
echo "</tr>";
echo "<tr>";
echo ' <td align="center"> <form method="POST" action="showcontact.php">
<input type="text" name="response" height="50pt"/> <br/>
<input type="submit" value="send" name="send"> </form> </td>';
echo "<td align='center'> <b> answer </b> </td>";
echo "</tr>";
if(isset($_POST['response'])) {
$response = $_POST['response'];
$sql = ("UPDATE contact SET response = '$response' WHERE id= $name[id]");
$rst = mysqli_query($con,$sql);
if($rst){
echo "<td align='center'> <b> sent </b> </td>" ;
echo " <td align='center'> </td>";
} else {
echo "<td align='center'> <b> did not send </b> </td>";
echo " <td align='center'> </td>";
echo "</table>";
}
}
}
?>
答案 0 :(得分:0)
将所有内容放在循环中会使您难以阅读代码。
您需要一个联系人ID来附加回复。
以下是我如何做的简要概述:
loop through contacts
row begins
display contact info
display response form
row ends
end loop
response form:
give it a post method
add a hidden contact id field <--
response input (text)
submit button
Form processing logic:
if this is a post request, and we have an id and response:
do your SQL update
我将表单处理放在脚本顶部的循环中,或放在另一页上。