如何使用php在另一个页面中显示单个记录详细信息

时间:2016-01-24 12:29:52

标签: php mysqli data-retrieval

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

<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

1 个答案:

答案 0 :(得分: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排序默认值。如果用户使用其他标题,则会根据需要切换。

希望这有效..

注意:有兴趣进行投票的人请说明原因