重新加载页面时,复选框选定的记录不会显示 [英] Checkbox selected records does not show when page reloaded
本文介绍了重新加载页面时,复选框选定的记录不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一个代码,用PHP从数据库中获取所有记录。并且用户可以使用复选框选择一些他想要的记录。所选记录显示在单独的页面中。但是当重新加载页面时,结果不会显示。我可以解决这个问题吗?
我尝试过:
此代码用于从数据库中提取所有记录并使用复选框提交
< div class =col-lg-8 card>
< table class =table table-striped table-hover table-bordered datatable>
< thead style =background:#967272; color:black;>
< tr>
< th style =width:50px;>< / th>
< th style =color:#3b3b3b;>公司名称< / th>
< th style =color:#3b3b3b;>服务< / th>
< th style =color:#3b3b3b;> email< / th>
< th style =color:#3b3b3b;> Logo< / th>
< / tr>
< / thead>
< tbody>
< form name =action =index.phpmethod =POST>
<?php
$ sql =select * from company_details;
$ result = $ con> query($ sql);
if($ result-> num_rows> 0){
?>
<?php
while($ row = $ result-> fetch_assoc()){
?>
< tr>
< td>
< center>< input type =checkboxname =check [<?php echo $ row ['id'];?>]value =1>< / center> ;
< / td>
< td>< input type =name =company_name []value =<?php echo $ row ['company_name'];?>>< / label>< ; / TD>
< td>< input type =name =service []value =<?php echo $ row ['service'];?>>< / label>< ; / TD>
< td>< input type =labelname =email []value =<?php echo $ row ['email'];?>>< / label> < / TD>
< td><?php echo'< img src ='。$ row ['image_path4']。'width =100height =100>'; ?>< / TD>
< / tr>
<?php}} // while循环结束?>
< / div>
< button type =submitclass =btn btn-hg btn-successname =AddEbooks>提交< / button>
< / form>
此代码显示所选记录
< div class =col-lg-8>
<?php
$ sql =select * from company_details;
$ result = $ con> query($ sql);
if($ result-> num_rows> 0){
while($ row = $ result-> fetch_assoc()){
$ ID = $行[ 'ID'];
/ *获取图书ID,现在我们必须从$ _POST中获取* /
格式的值if(array_key_exists($ ID,$ _POST [check])){
$ ischecked = $ _ POST [check] [$ ID];
/ *看看它的值是否为1.如果是,则表示已检查* /
if($ ischecked == 1){
?>
< div class =col-lg-6style =padding-top:20px;>
< section>
< div class =well>
< div class =card>
< div class =row>
< div class =col-md-4>
<?php echo'< img src ='。$ row ['image_path4']。'width =100height =100>'; ?>
< / div>
< div class =col-md-8 px-3>
< div class =card-block px-3>
< h4 class =card-title><?php echo $ row ['company_name']; ?>< / H4>
< div>
< label>服务类型< / label>
<?php echo $ row ['service']; ?>
< / div>
< div>
< label> email< / label>
<?php echo $ row ['email']; ?>
< / div>
< div>
< label>关于< / label>
<?php echo substr($ row ['details'],0,300); ?>
< / div>
< a href =#class =btn btn-success>阅读更多< / a>
< / div>
< / div>
< / div>
< / div>
< / section>
< / div>
<?php
}
}
}
}
?>
< / div>
解决方案
sql =select * from company_details;
result =
CON组>查询(
I have developed a code to fetch all records from database using PHP . and the user can select some records as he wish using checkbox. The selected records are shown in a separate page.but when page is reloaded the results are not shown.how can I solve this?
What I have tried:
This code is used for fetching all records from database and use checkboxes to submit
<div class="col-lg-8 card"> <table class="table table-striped table-hover table-bordered datatable"> <thead style="background: #967272; color: black;"> <tr> <th style="width: 50px;"></th> <th style="color: #3b3b3b;">Company Name</th> <th style="color: #3b3b3b;">Service</th> <th style="color: #3b3b3b;">email</th> <th style="color: #3b3b3b;">Logo</th> </tr> </thead> <tbody> <form name="" action="index.php" method="POST"> <?php $sql="select * from company_details "; $result = $con->query($sql); if ($result->num_rows > 0) { ?> <?php while($row = $result->fetch_assoc()) { ?> <tr> <td> <center><input type="checkbox" name="check[<?php echo $row['id'];?>]" value="1"></center> </td> <td><input type="" name="company_name[]" value="<?php echo $row['company_name'];?>"></label></td> <td><input type="" name="service[]" value="<?php echo $row['service'];?>"></label></td> <td><input type="label" name="email[]" value="<?php echo $row['email'];?>"></label></td> <td><?php echo '<img src="' . $row['image_path4']. '" width="100" height="100">'; ?></td> </tr> <?php }} //end of while loop ?> </div> <button type="submit" class="btn btn-hg btn-success" name="AddEbooks">Submit</button> </form>
This code shows the selected records
<div class="col-lg-8"> <?php $sql="select * from company_details"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $ID=$row['id']; /* Get the Book ID and now we have to fetch from $_POST the value from the form */ if (array_key_exists($ID, $_POST["check"])) { $ischecked=$_POST["check"][$ID]; /* See if this has a value of 1. If it does, it means it has been checked */ if ($ischecked==1) { ?> <div class="col-lg-6" style="padding-top: 20px;"> <section> <div class="well" > <div class="card" > <div class="row "> <div class="col-md-4"> <?php echo '<img src="' . $row['image_path4']. '" width="100" height="100">'; ?> </div> <div class="col-md-8 px-3"> <div class="card-block px-3"> <h4 class="card-title"><?php echo $row ['company_name']; ?></h4> <div > <label>Service Type</label> <?php echo $row ['service']; ?> </div> <div > <label>email</label> <?php echo $row ['email']; ?> </div> <div > <label>About</label> <?php echo substr($row['details'], 0, 300); ?> </div> <a href="#" class="btn btn-success">Read More</a> </div> </div> </div> </div> </section> </div> <?php } } } } ?> </div>
解决方案
sql="select * from company_details ";
result =
con->query(
这篇关于重新加载页面时,复选框选定的记录不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文