dqfkd82886 2017-10-27 07:37
浏览 26
已采纳

使用基于id [duplicate]的join子句从两个表中获取

I am making a table on bootstrap fetching data in this table from two table in same database here is picture of my database select two table fron on database

here is my code i am using to fetch value from databases

 <table class="table table-hover table-striped">
                                        <thead>
                                            <tr>
                                                <th>Id</th>
                                                <th>File-name</th>
                                                <th>Purpose</th>
                                                <th>Recieved-By </th>
                                                 <th>Processed-By</th>
                                                 <th>Address</th>
                                                 <th>Contact-No</th>
                                                 <th>Recieved-Date</th>
                                                 <th>Update-date</th>
                                                 <th>status</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                        <?php
                          $p_query= "SELECT id, file_name, recieved_by, processed_by, purpose, address, contact_no, date,update_date,reason FROM files INNER JOIN update_table ON files.id=update_table.id"; 
                          $con=mysqli_connect("localhost","root","","fileprogramsysteeem");
                          $p_run=mysqli_query($con,$p_query);
                            if(mysqli_num_rows($p_run)){
                             while($row=mysqli_fetch_array($p_run))
                             {
                                $id=$row['id'];
                                $file=$row['file_name'];
                                $purpose=$row['purpose'];
                                $recieve=$row['recieved_by'];
                                $processed=$row['processed_by'];
                                $address=$row['address'];
                                $contact=$row['contact_no'];
                                $date=$row['date'];
                                $up_date=$row['update_date'];
                                $status=$row['reason'];


                            ?>
                                            <tr>

                                                 <td><a  href="post.php?post_id=<?php echo $id?>"><?php echo $id;?></a></td>
                                                 <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $file;?></a></td>
                                                 <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $purpose;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $recieve;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $processed;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $address;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $contact;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $date;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $id?>"><?php echo $up_date;?></a></td>
                                                <td style="color:#337AB7;"><?php echo $id?>"><?php echo $status;?></td>
                                            </tr>
                                            <?php 
                                      }
                                    }
                                   ?>
                                        </tbody>
                                    </table>

Now after applying this code i am getting this error :

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result

I have to select file_name, received _by, processed_by, purpose, address, contact_no, date from table files and update_date , reason from table update_table

</div>
  • 写回答

1条回答 默认 最新

  • duandingcu7010 2017-10-27 07:56
    关注
    $p_query= "SELECT files.* , update_table.* FROM files INNER JOIN update_table ON files.id=update_table.id"; 
                          $con=mysqli_connect("localhost","root","","fileprogramsysteeem");
    

    try this may be this would help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?