【发布时间】:2016-12-31 14:43:20
【问题描述】:
请尝试连接两个表以获取记录,并在一个表中回显记录。
第一个是表'customer',第二个是表'beneficiary1'。
什么时候,我尝试加入表格然后只获取记录
(i.e receiver_id and receiver_name) 的 'beneficiary1' 但该表未显示另一个表为“客户”的记录(即 profile_pictures)。
这是什么原因造成的,我已经尝试了所有我能想到的代码!
<?php
mysql_connect("localhost","root");
mysql_select_db("bank_db");
$sender_id=$_SESSION["login_id"];
$res=mysql_query("SELECT c.* , b.* FROM customer c,beneficiary1 b
WHERE c.id=b.sender_id
AND b.sender_id='$sender_id'
ORDER BY c.id ASC LIMIT 4 ");
while($row=mysql_fetch_assoc($res))
{
if($row['profile_pictures'] == ""){
$output6 = "<img src='default.png' class='img-circle' alt='image' width='40' height='40'/>";
}else{
$output6 = "<img src='src='uploads/".$row['profile_pictures']."' class='img-circle' alt='image' width='50' height='50'/>";
}
?>
<tr>
<td class="center"><?php echo $row['profile_pictures']; ?></td>
<td><span class="text-small block text-light">0059687310 - <?php echo $row['reciever_id']; ?></span><span class="text-large"><?php echo $row['reciever_name']; ?></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>
<?php
}
?>
为了受益人!
<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';
$sql1="SELECT * FROM customer WHERE id='reciever_id' ";
$result1= mysql_query($sql1) or die(mysql_error());
while($rows= mysql_fetch_array($result1)){
.$rows[14]. //profile_pictures
}
?>
【问题讨论】:
-
去掉查询中$senderid周围的单引号
-
图像没有显示静止!
-
一些合理的代码缩进是个好主意。它帮助我们阅读代码,更重要的是,它将帮助 您调试您的代码 Take a quick look at a coding standard 为您自己谋取利益。您可能会被要求在几周/几个月内修改此代码,最后您会感谢我的。
-
@jophab 单引号不是问题
-
您是否尝试过使用 phpMyAdmin 或类似的查询工具运行此查询?
标签: php html mysql echo jointable