我想把我使用phpmysql得到的表转换成带有复选框的treeview,最好的方法是什么。
表
至
树视图
这是我的密码:
<h4>Select Students</h4>
<table class="table table-bordered" id="example">
<thead>
<tr>
<th>#</th>
<th>Class</th>
<th>Roll/SL No.</th>
<th>Adm No.</th>
<th>Student Name</th>
<th>Father Name</th>
</tr>
</thead>
<?php
$result = mysqli_query($conn7,"SELECT * FROM student_info WHERE school_id='$school_id' order by st_class_name ASC, roll_no + 0 ASC, st_name ASC");
while($row = mysqli_fetch_assoc($result)){
?>
<tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['st_id']; ?>"></td>
<td><?php echo $row["st_class_name"]; ?></td>
<td><?php echo $row["roll_no"]; ?></td>
<td><?php echo $row["admission_no"]; ?></td>
<td><?php echo $row["st_name"]; ?></td>
<td><?php echo $row["father_name"]; ?></td>
</tr>
<?php } ?>
</table>
我尝试过的新代码-
<?php
$prev_class_id = 1;
$sql_query_stu = mysqli_query($conn7,"SELECT * FROM student_info where school_uni_id='$school_uni_id' order by st_class ASC, roll_no + 0 ASC, st_name ASC");
while($display_stu = mysqli_fetch_assoc($sql_query_stu)){
$class_id = $display_stu['st_class'];
$prev_class_id = prev($class_id);
$class_id = $display_stu['st_class_name'];
if($class_id != $prev_class_id){
?>
<li>
<i class="fa fa-plus fa-lg"></i>
<label>
<input id="xnode-0-1" data-id="custom-0-1" type="checkbox" value="<?php echo "$class_id"; ?>"/>
<?php echo $display_stu['st_class_name']; ?>
</label>
</li>
<?php }} ?>
结果-mytree
我的mysql表中的每个学生都有class\u id和class\u name
1条答案
按热度按时间uttx8gqw1#
性能问题是由嵌套的数据库查询造成的。使用包含联接的单个查询可以更好地实现这一点。我必须猜测这个查询,因为您还没有显示表定义。
然后您的php代码需要执行以下操作:
关于
$previous_class_id
用于按类分解结果的呈现。一些语言(PL/1
例如,查找-)有一个但在php中,你必须伪造它。
供将来参考:很难从你的问题中猜出你真正的问题是什么。你花时间来更准确地提出问题是绝对值得的。