請嘗試連接兩個表來獲取記錄,以回顯一個表中的記錄。當我連接兩個表時,Sql無法獲取列的記錄
第一個是'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
}
?>
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';
$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周圍的單引號 – jophab
圖像沒有顯示出來! –
一些明智的代碼縮進將是一個好主意。它可以幫助我們閱讀代碼,更重要的是,它可以幫助您**調試您的代碼** [快速瀏覽編碼標準](http://www.php-fig.org/psr/psr-2/ )爲了您自己的利益。您可能會被要求在幾周/幾個月內修改此代碼 ,最後您會感謝我。 – RiggsFolly