我的数据库中有两个表'CUSTOMER'和'BENEFICIARY',我想调出他们的一些记录,都放在一个表中。 “CUSTOMER”表有“profile_picture”列,“BENEFICIARY”表有“receiver_name”和“receiver_id”列,最后两者分别有共同的 Id 和 sender_id 列,这显然是客户的登录 ID。
问题是,我完全不知道如何将两条记录显示在我希望在客户仪表板上显示的一个表中,我希望用户在该表中将他的两个受益人姓名和个人资料图像显示在该表中。
下面是我的两个不同的查询:
FOR BENEFICIARY!
<php
include '_inc/dbconn.php';
$sender_id=$_SESSION["login_id"];
$sql="SELECT * FROM beneficiary WHERE sender_id='$sender_id' AND status='ACTIVE' ";
$result= mysql_query($sql) or die(mysql_error());
while($rws= mysql_fetch_array($result)){
.$rws[3]. //receiver_id
.$rws[4]. //receiver_name
}
?>
对于客户!
<php
include '_inc/dbconn.php';
$sender_id=$_SESSION["login_id"];
$sql1="SELECT * FROM customer WHERE id='$sender_id' ";
$result1= mysql_query($sql1) or die(mysql_error());
while($rows= mysql_fetch_array($result1)){
.$rows[14]. //profile_pictures
}
?>
要回显的 HTML 表格!
<tr>
<td class="center">.$rows[14].</td>
<td><span class="text-small block text-light">.$rws[3].</span><span class="text-large">.$rws[4].</span><a href="#" class="btn"><i class="fa fa-pencil"></i></a></td>
<td class="center">
<div>
<div class="btn-group">
<a class="btn btn-transparent-grey dropdown-toggle btn-sm" data-toggle="dropdown" href="#">
<i class="fa fa-cog"></i> <span class="caret"></span>
</a>
<ul role="menu" class="dropdown-menu dropdown-dark pull-right">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<i class="fa fa-edit"></i> Edit
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<i class="fa fa-share"></i> Share
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">
<i class="fa fa-times"></i> Remove
</a>
</li>
</ul>
</div>
</div></td>
</tr>
最佳答案
在客户表中使用JOIN查询
SELECT beneficiary.receiver_name,customer.profile_picture
FROM CUSTOMER
INNER JOIN BENEFICIARY
ON BENEFICIARY.sender_id=CUSTOMER.sender_id;
关于php - 如何将两个不同的mysql查询的结果合并到一个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39068081/