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


how can i Display individual records details in another page using php

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

<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

表标题内容更改为锚标记例如作为

<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 默认排序。 如果用户使用其他标题,它将根据需要进行切换。

希望这有效..

注:对投反对票感兴趣的人,请注明原因