【问题标题】:how to fetch data and display it in the same php page如何获取数据并将其显示在同一个 php 页面中
【发布时间】:2015-12-28 19:18:36
【问题描述】:

当单击其他表的一行时,我想从同一页面中的一个表中获取一些数据。

这是我正在尝试做的事情的代码,但我被卡住了:

<?php
$db_table="area";  
$db_query='select areaid,area_name from ' . $db_table;
$query_result=mysqli_query($dbc,$db_query) or die('error querying db');?>

<div id="area1" >
    <h3>Select ony two area from Category </h3>
         <form>
             <fieldset style="float: left; width: 25%">
                  <legend>Project Area</legend>
                      <table border=1>
                         <tr> 
                            <th> </th>
                            <th> Area Name </th>
                         </tr>
                      <?php 
                        while($row=mysqli_fetch_array($query_result)){ 
                      ?>
                         <tr id="<?php echo $row['areaid'];?>" class="area" onlick="showfaculty()">
                              <td> <input class="selectarea" type="radio"  name = "proarea" value="<?php echo $row['areaid'];?>"></td>
                              <td> <?php echo $row['area_name']; ?></td>
                        </tr>

                        <?php }
                         echo '</table></br></br>
          </fieldset>

          <fieldset id="avaguide" style="width: 25%">
                   <legend>Available Guide</legend>
                        <table border=1>
                             <tr> 
                                <th> </th>
                                 <th> Available Guides </th>
                             </tr>';
                            $db_table2="facultytable"; 
                            $db_query='select facultyID,facultName from ' .                       $db_table2.' where project_count<2';
                            $query_result=mysqli_query($dbc,$db_query) or die('error querying db');
                            while($row=mysqli_fetch_array($query_result)){
                            ?>
                            <tr id="<?php echo $row['facultyID'];?>" class="area">
                                   <td> <input class="selectguide" type="radio"  name = "areaguide" value="<?php echo $row['facultyID'];?>"></td>
                                   <td> <?php echo $row['facultName']; ?></td>
                    </tr>
                     <?php }        
                        echo '</table></fieldset>

                   </form>
            </div>;`

现在我的代码运行良好,它同时显示了区域和教员表。但它显示完整的教师表。我想要做的是,当单击区域表的行时,应该调用某个函数,该函数从表 Faculty_area(a_id, f_id) 中获取所选区域 id 的所有教员 id,并且教员表仅显示获取的教员的名称教师编号下面是该函数的一个示例。

function showFaculty($aeraid){
         $db_table2="faculty_area"; 
         $db_query='select f_id from ' . $db_table2.' where a_id = '.$areaid;
         $query_result=mysqli_query($dbc,$db_query) or die('error querying db');
         while($row=mysqli_fetch_array($query_result)){ some code that can be used to display faculty table with feteched f_id}

请告诉我该怎么做。

【问题讨论】:

  • 请努力帮助其他人了解您的问题。在此处粘贴表格结构并正确格式化您的文本。
  • 你的代码到底是什么?或者,您是要求我们为您编码吗?
  • 请不要期望下面会出现神奇的答案。这不是“堆栈如何滚动”
  • 欢迎来到 SO。请阅读What topics can I ask aboutHow to ask a good questionthe perfect question SO 不是免费的编码服务

标签: php jquery mysql


【解决方案1】:

在我看来,完成这项任务的最佳方式是使用 AJAX,或者您可以在 PHP 上使用 JS 和 RESTful 服务构建一个页面应用程序。我喜欢 AngularJS 作为前端。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 2020-02-13
    • 2021-04-20
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多