[英]How to make the form dynamic
Lets say inside my sql have some data: 可以说我的sql内部有一些数据:
name | 名称| table_no
table_no
Apple | 苹果| c1
c1
Grape | 葡萄| c1
c1
if($result->num_rows > 0){ //read the data inside sql and display out
while($row = $result->fetch_assoc()){
echo "Name: ". $row['name']. "<br>". "Table No.: ". $row['table_no']. "<br>";
}
}else{ // insert the data if inside sql have no data of table_no
if($_SERVER['REQUEST_METHOD'] == "POST"){
$value = $_POST['value'];
$table = $_POST['table'];
}
$sql = "INSERT INTO testing (name, table_no) VALUES ('$value', '$table')";
mysqli_query($conn, $sql);
}
?>
<form method="post" action="">
<h2>C1</h2>
<input type="hidden" value="c1" name="table">
<input type="text" name="value">
<input type="submit">
</form>
<form method="post" action="">
<h2>C2</h2>
<input type="hidden" value="c2" name="table">
<input type="text" name="value">
<input type="submit">
</form>
My problem is, how to make the webpage more dynamic that can automatically change to a blank form that can be fill in the data(table_no) and if the form already has the data it will display the data instead of showing the blank form to let user fill in. 我的问题是,如何使网页更具动态性,可以自动更改为可以填写数据的空白表格(table_no),如果该表格已具有数据,它将显示数据而不是显示空白表格用户填写。
You can dynamically update the value in your input. 您可以动态更新输入中的值。 Assuming $result is the result of your SQL query and there is a field named C1 in $result, here an example for your form C1:
假设$ result是您的SQL查询的结果,并且$ result中有一个名为C1的字段,以下是表格C1的示例:
<!-- langage: html -->
<form method="post" action="">
<h2>C1</h2>
<input type="hidden" value="<?php echo $result['c1']; ?>" name="table">
<input type="text" name="value">
<input type="submit">
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.