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

时间:2017-10-27 07:37:08

标签: php html mysql

我在 bootstrap 上创建一个表格,从两个表中获取此表中的数据数据库这里是我的数据库的图片 select two table fron on database

这是我用于从数据库中获取值的代码

 <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>

现在应用此代码后,我收到此错误:

  

警告:mysqli_num_rows()期望参数1为mysqli_result

我必须从表文件 update_date,原因中选择 file_name,收到_by,processed_by,目的,地址,contact_no,日期 update_table

1 个答案:

答案 0 :(得分:1)

$p_query= "SELECT files.* , update_table.* FROM files INNER JOIN update_table ON files.id=update_table.id"; 
                      $con=mysqli_connect("localhost","root","","fileprogramsysteeem");
试试这可能会有所帮助