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

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

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

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result

我必须从表文件中选择file_name、receive_by、processed_by、目的、地址、contact_no、日期以及update_date、原因update_table

最佳答案

$p_query= "SELECT files.* , update_table.* FROM files INNER JOIN update_table ON files.id=update_table.id"; 
                      $con=mysqli_connect("localhost","root","","fileprogramsysteeem");

试试这个可能会有帮助

关于php - 使用基于id的join子句从两个表中获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46969814/

相关文章:

javascript - 响应ajax方法的innerHtml

php - 检查一个字符串是否是一个 URL

php - 从下拉列表中获取值以在 MySQL 查询中使用

javascript - 在 iframe 循环中显示 URL

php - 如何在 uploadify 中传递自定义值

html - 子 div 立即消失而不是像父 div 那样过渡

mysql - SQL索引优化WHERE查询

MySQL 约束 - 一组中的一列必须是非空的?

java - 如何以系统时间间隔15分钟从数据库获取数据?

php - Zend 框架 : Proper way to interact with database?