Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何基于php数据库值动态更改HTML中的内容?_Php_Html_Mysql_Web - Fatal编程技术网

如何基于php数据库值动态更改HTML中的内容?

如何基于php数据库值动态更改HTML中的内容?,php,html,mysql,web,Php,Html,Mysql,Web,我有一个基于web的应用程序,带有PHP(mysql)后端。我有一个页面可以输入在特定事件中获得的等级和职位。我需要的页面显示复选框(成绩)只有当他们没有被输入之前。因此,我的数据库中有这列P1,如果这是NULL,我需要显示复选框 这就是我在php方面所做的 <?php $PID = (int)$_GET['PID']; $con = new mysqli("localhost","my_user","my_password",'events'); $result = $con->q

我有一个基于web的应用程序,带有PHP(mysql)后端。我有一个页面可以输入在特定事件中获得的等级和职位。我需要的页面显示复选框(成绩)只有当他们没有被输入之前。因此,我的数据库中有这列P1,如果这是NULL,我需要显示复选框

这就是我在php方面所做的

<?php
$PID = (int)$_GET['PID'];
$con = new mysqli("localhost","my_user","my_password",'events');
$result = $con->query("SELECT * FROM eventlist WHERE Eid=$PID");
global $output;
$row =  $result->fetch_assoc();
echo '<h1>'.$row["Ename"].'</h1>';
if($row["P1"]==NULL)
?>

我需要在P1中显示的是NULL,如下所示

<h2>Slot 1</h2>
<h3>Enter Result</h3>
<div id="c1" class="radio">
  <label><input type="radio" name="opt1radio" value=30>First</label>
  <label><input type="radio" name="opt1radio" value=20>Second</label>
  <label><input type="radio" name="opt1radio" value=10>Third</label>
</div>
<h3>Enter Grade</h3>
<div id="c2" class="radio">
  <label><input type="radio" name="opt2radio" value=5>A</label>
  <label><input type="radio" name="opt2radio" value=4>B</label>
  <label><input type="radio" name="opt2radio" value=3>C</label>
  <label><input type="radio" name="opt2radio" value=2>D</label>
  <label><input type="radio" name="opt2radio" value=0>DQ</label>
</div>
<div id="submit">
  <button onclick="myFunction()" type="button" class="btn btn-success">Submit</button>
</div>
插槽1
输入结果
弗斯特
第二
第三
入级
A.
B
C
D
DQ
提交

我怎样才能做到这一点,而不在每一行HTML中添加echo。

您可以试试这个。如果您不想使用
echo
,只需在
If
中包含
html
,而不在
php
区域中包含
html

<?php
 $PID = (int)$_GET['PID'];
    $con = new mysqli("localhost","my_user","my_password",'events');
    $result = $con->query("SELECT * FROM eventlist WHERE Eid=$PID");
    global $output;
    $row =  $result->fetch_assoc();
    echo '<h1>'.$row["Ename"].'</h1>';
    if($row["P1"]==NULL){
  ?>

<h2>Slot 1</h2>
    <h3>Enter Result</h3>
    <div id="c1" class="radio">
      <label><input type="radio" name="opt1radio" value=30>First</label>

      <label><input type="radio" name="opt1radio" value=20>Second</label>

      <label><input type="radio" name="opt1radio" value=10>Third</label>
    </div>

   <h3>Enter Grade</h3>  
   <div id="c2" class="radio">
      <label><input type="radio" name="opt2radio" value=5>A</label>

      <label><input type="radio" name="opt2radio" value=4>B</label>

      <label><input type="radio" name="opt2radio" value=3>C</label>

      <label><input type="radio" name="opt2radio" value=2>D</label>

       <label><input type="radio" name="opt2radio" value=0>DQ</label>
    </div>
    <div id="submit">

      <button onclick="myFunction()" type="button" class="btn btn-success">Submit</button>
    </div>
<?php }?>

插槽1
输入结果
弗斯特
第二
第三
入级
A.
B
C
D
DQ
提交

我认为您唯一缺少的是一行一行地检索所有行,您可以使用:
while($row=$result->fetch_assoc()){
然后将所有代码放在如下位置:

<?php
 $PID = (int)$_GET['PID'];
    $con = new mysqli("localhost","my_user","my_password",'events');
    $result = $con->query("SELECT * FROM eventlist WHERE Eid=$PID");
    global $output;
    while ($row = $result->fetch_assoc()) {
    echo '<h1>'.$row["Ename"].'</h1>';
    if($row["P1"]==NULL){
  ?>

<h2>Slot 1</h2>
    <h3>Enter Result</h3>
    <div id="c1" class="radio">
      <label><input type="radio" name="opt1radio" value=30>First</label>

      <label><input type="radio" name="opt1radio" value=20>Second</label>

      <label><input type="radio" name="opt1radio" value=10>Third</label>
    </div>

   <h3>Enter Grade</h3>  
   <div id="c2" class="radio">
      <label><input type="radio" name="opt2radio" value=5>A</label>

      <label><input type="radio" name="opt2radio" value=4>B</label>

      <label><input type="radio" name="opt2radio" value=3>C</label>

      <label><input type="radio" name="opt2radio" value=2>D</label>

       <label><input type="radio" name="opt2radio" value=0>DQ</label>
    </div>
    <div id="submit">

      <button onclick="myFunction()" type="button" class="btn btn-success">Submit</button>
    </div>
<?php } }?>

插槽1
输入结果
弗斯特
第二
第三
入级
A.
B
C
D
DQ
提交
去掉while,代码将只显示第一个结果


希望能有所帮助!

如果答案有效,请接受它,以便其他人知道什么对OP有效。