【问题标题】:how can i Display individual records details in another page using php我如何使用 php 在另一个页面中显示单个记录的详细信息
【发布时间】:2016-04-30 18:30:18
【问题描述】:

以下代码仅显示记录列表,当我们单击链接时,我希望它转到另一个页面,该页面假定仅显示所选标题的记录详细信息。目前,它总是显示相同的细节。现在只显示所选标题的记录详细信息的解决方案是什么

<table class="table table-striped table-bordered bootstrap-datatable datatable">// the record list table 
          <thead>
            <tr>
              <th>ID</th>
              <th>Course Name</th>
              <th>Duration</th>
              <th>Subjects</th>
              <th>Status</th>
              <th>Actions</th>
            </tr>
          </thead>   
          <tbody>
            <?php $getcourseslist = find_all("select * from course");
                while(@$getcourses = fetch_array($getcourseslist)){
             ?>
          <tr>
            <td><?= $getcourses->id; ?></td>
            <td> <a href="viewcoursedetails.php"><?= $getcourses->title;?></td></a>
            <td><?= $getcourses->duration/12; ?> Years</td>
            <td class="center">
              <?php $getsubjects= find_all("select * from subjects where courseid='$getcourses->id'");
                while(@$getsubs = fetch_array($getsubjects)){
               ?>
               <?= $getsubs->name; ?><br>
              <?php } ?>
              </td>
            <td class="center">
              <?php if($getcourses->status == 1){ ?>
              <span class="label label-success">Active</span>
              <?php }
                else{
               ?>
               <span class="label label-important">Blocked</span>
              <?php } ?>
            </td>
            <td class="center">

              <a class="btn btn-success" href="editcourse.php?course=<?= $getcourses->id; ?>">
                <i class="halflings-icon white edit"></i>  
              </a>
              <?php if($getcourses->status == 1){ ?>
              <a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=block&&page=courses">
                <i class="halflings-icon white trash"></i> 
              </a>
              <?php }
                else{
               ?>
              <a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=unblock&&page=courses">
                <i class="halflings-icon white trash"></i> 
              </a>
              <?php } ?>
            </td>
          </tr>
          <?php } ?>

          </tbody>
        </table>            
      </div>
    </div><!--/span-->

  </div><!--/row-->

// 下面的代码应该只显示所选标题的记录详细信息。目前,它总是显示与上一页相同的详细列表。//

课程详情查看





             <tr>
                <th>ID :</th>
                <td><?= $getcourses2->id; ?></td>
              </tr>
              <tr>
                <th>Course Name :</th>
                <td><?= $getcourses2->title; ?></td>
              </tr>
              <tr>
                <th>Duration :</th>
                <td><?= $getcourses2->duration/12; ?> Years</td>
              </tr>
              <tr>
                <th>Subjects :</th>
                <td class="center">
              <?php $getsubjects= find_all("select * from subjects where courseid='$getcourses->id'");
                while(@$getsubs = fetch_array($getsubjects)){
               ?>
               <?= $getsubs->name; ?><br>
              <?php } ?>
              </td>
              </tr>
              <tr>
                <th>Monthly Fee :</th>
                <td><?= $getcourses2->monthlyfee ; ?></td>
              </tr>
              <tr>
                <th>Examination Fee :</th>
                <td><?= $getcourses2->examinationfee; ?></td>
              </tr>
              <tr>
                <th>Addmission Fee :</th>
                <td><?= $getcourses2->addmissionfee; ?></td>
              </tr>
              <tr>
                <th>Status :</th>
                <td class="center">
              <?php if($getcourses2->status == 1){ ?>
              <span class="label label-success">Active</span>
              <?php }
                else{
               ?>
               <span class="label label-important">Blocked</span>
              <?php } ?>
            </td>
              </tr>
              <tr>
                <th>Actions :</th>
                 <td class="center">

              <a class="btn btn-success" href="editcourse.php?course=<?= $getcourses->id; ?>">
                <i class="halflings-icon white edit"></i>  
              </a>
              <?php if($getcourses2->status == 1){ ?>
              <a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=block&&page=courses">
                <i class="halflings-icon white trash"></i> 
              </a>
              <?php }
                else{
               ?>
              <a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=unblock&&page=courses">
                <i class="halflings-icon white trash"></i> 
              </a>
              <?php } ?>
            </td>
          </tr>
          <?php } ?>


              </thead>
              <tbody>

            </table>
enter code here

【问题讨论】:

  • 好的。您有什么问题要问我们?
  • 再详细一点应该会更好。更具体一些,并尝试粘贴输出内容及其外观。

标签: php mysqli data-retrieval


【解决方案1】:

将表格标题内容更改为锚标签 例如作为

<a href="?sortby=id">ID</a>

然后在服务器端,将查询处理为

$sort = 'id'; if(isset($_REQUEST['sortby'])&&str_replace(' ','',$_REQUEST['sortby'])!="") $sort = $_REQUEST['sortby']; $queryText= "select * from table_name where order by ".$sort;

确保href传递的值是你sql表中的属性名

此代码使查询按 id 默认排序。如果用户使用另一个标题,它将根据需要切换。

希望这行得通..

注意:有意投反对票的人,请说明原因

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-26
    • 2017-03-21
    • 1970-01-01
    • 2021-10-17
    • 2016-09-03
    • 1970-01-01
    • 2016-06-26
    • 2020-11-01
    相关资源
    最近更新 更多