HTML表格和复选框

我有1个带有复选框的表..
我想要发生的是设置复选框的值 成为 student_id </ strong> </ p>

这是我的代码:</ p>

 &lt;?php 
require_once('xcon .PHP');

$ q = mysql_query(“SELECT * FROM Students”);
?&gt;

&lt; table&gt;&lt; br&gt;&lt; br&gt;
&lt; thead&gt;
&lt; tr&gt;
&lt; th&gt;选择&lt; / th&gt;
&lt; th&gt;学生ID&lt; / th&gt;
&lt; th&gt;学生名字&lt; / th&gt;
&lt; th&gt;学生姓氏&lt; / th&gt;
&lt; ; th&gt; Level&lt; / th&gt;
&lt; / tr&gt;
&lt; / thead&gt;
&lt;?php
while($ row = mysql_fetch_assoc($ q)){

echo“&lt; TBODY&gt;“中;

echo“&lt; tr&gt;”;
echo“&lt; td&gt;&lt; input type ='checkbox'name ='checkbox []'&gt;&lt; / td&gt;”;
echo“&lt; td&gt; “。$ row ['student_id']。”&lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['fname']。”&lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['lname']。”&lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['yearlevel']。”&lt; / td&gt;“;
echo” &lt; / tr&gt;“;
echo”&lt; / tbody&gt;“;
}
?&gt;

&lt; / table&gt;
</ code> </ pre>

我似乎遇到了解决这个问题的麻烦,我感到很困惑。</ p>

提前感谢您的帮助。</ p>
</ div>

展开原文

原文

I have 1 table with checkboxes in it.. What I want to happen is to set the value of the checkbox to be the student_id

Here's my code:

      <?php 
        require_once('xcon.php'); 
        $q = mysql_query("SELECT * FROM Students");
      ?>

      <table><br><br>
            <thead>
                <tr>
                    <th>Choice</th>
                    <th>Student ID</th>
                    <th>Student First Name</th>
                    <th>Student Last Name</th>
                    <th>Level</th>
                </tr>
            </thead>
            <?php
                 while($row = mysql_fetch_assoc($q)){

                    echo "<tbody>";    
                    echo "<tr>";
                    echo "<td><input type = 'checkbox' name = 'checkbox[]' ></td>";
                    echo "<td>".$row['student_id']."</td>";
                    echo "<td>".$row['fname']."</td>";
                    echo "<td>".$row['lname']."</td>";
                    echo "<td>".$row['yearlevel']."</td>";
                    echo "</tr>";
                    echo "</tbody>";
                }  
            ?> 

    </table>

I seem to be having the trouble of getting the logic in this and i got confused.

Thank you in advance for your help.

3个回答



  echo“&lt; td&gt;&lt; input type ='checkbox'name ='checkbox []'value ='{  $ row ['student_id']}'&gt;&lt; / td&gt;“; 
</ code> </ pre>
</ div>

展开原文

原文

echo "<td><input type = 'checkbox' name = 'checkbox[]' value='{$row['student_id']}'></td>";

dqqg0811
dqqg0811 请为您的答案添加一些解释!
接近 5 年之前 回复



value </ code>属性添加到您的复选框,其值为学生ID:</ p>

while($ row = mysql_fetch_assoc($ q)){

echo“&lt; tbody&gt;”;

echo“&lt; tr&gt;”;
echo“&lt; td&gt;&lt; input type ='checkbox'name ='checkbox []'value ='”。$ row ['student_id']。“'&gt; &lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['student_id']。”&lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['fname'] 。“&lt; / td&gt;”;
echo“&lt; td&gt;”。$ row ['lname']。“&lt; / td&gt;”;
echo“&lt; td&gt;”。$ row ['yearlevel ']。“&lt; / td&gt;”;
echo“&lt; / tr&gt;”;
echo“&lt; / tbody&gt;”;
}
</ code> </ pre>

值得注意的是</ strong>如果选中该复选框,复选框的值只会发布到您表单的目标。</ p>
</ div>

展开原文

原文

Add a value attribute to your checkbox with a value of the student id:

while($row = mysql_fetch_assoc($q)){

    echo "<tbody>";    
    echo "<tr>";
    echo "<td><input type = 'checkbox' name = 'checkbox[]' value='".$row['student_id']."'></td>";
    echo "<td>".$row['student_id']."</td>";
    echo "<td>".$row['fname']."</td>";
    echo "<td>".$row['lname']."</td>";
    echo "<td>".$row['yearlevel']."</td>";
    echo "</tr>";
    echo "</tbody>";
}

It's worth noting that values of checkboxes will only be posted through to your form's target if the box is checked.

dtc88867
dtc88867 没问题,很高兴我可以提供帮助。
接近 5 年之前 回复
doujia4041
doujia4041 这将是我的观点..我希望标记的值如果选中复选框..感谢您的帮助:)
接近 5 年之前 回复



我认为你看起来如下。将值属性添加到复选框输入字段,值应为$ row ['student_id']。< / p>

 &lt;?php 
while($ row = mysql_fetch_assoc($ q)){

echo“&lt; tbody&gt;”;

echo“&lt; tr&gt;”;
echo“&lt; td&gt;&lt; input type ='checkbox'name ='checkbox []'value ='”。$ row ['student_id']。“'&gt; &lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['student_id']。”&lt; / td&gt;“;
echo”&lt; td&gt;“。$ row ['fname'] 。“&lt; / td&gt;”;
echo“&lt; td&gt;”。$ row ['lname']。“&lt; / td&gt;”;
echo“&lt; td&gt;”。$ row ['yearlevel ']。“&lt; / td&gt;”;
echo“&lt; / tr&gt;”;
echo“&lt; / tbody&gt;”;
}
?&gt;

</ code> </ pre>
</ div>

展开原文

原文

I think you are looking as follows.Add value atribute to checkbox input field and value should be $row['student_id'].

<?php
                 while($row = mysql_fetch_assoc($q)){

                    echo "<tbody>";    
                    echo "<tr>";
                    echo "<td><input type = 'checkbox' name = 'checkbox[]' value='".$row['student_id']."' ></td>";
                    echo "<td>".$row['student_id']."</td>";
                    echo "<td>".$row['fname']."</td>";
                    echo "<td>".$row['lname']."</td>";
                    echo "<td>".$row['yearlevel']."</td>";
                    echo "</tr>";
                    echo "</tbody>";
                }  
            ?> 

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐