Please am trying to join two tables to fetch the record echo the records in one table.
The first is table 'customer' and the second is table 'beneficiary1'.
When, I try to join the tables then only get the records (i.e receiver_id and receiver_name)
of 'beneficiary1'
but the table doesn't show the record (i.e profile_pictures) of the other table being 'customer'.
What could have caused this, i've tried all the codes i could think of!
<?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
}
?>
FOR CUSTOMER
<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
}
?>
Append with concat dot with double quotes for $sender_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 ");
For joining purpose I think you need to re-write your query on following way :
$res = mysql_query("SELECT c.* , b.* FROM customer c JOIN beneficiary1 b ON c.id = b.sender_id WHERE b.sender_id = $sender_id ORDER BY c.id ASC LIMIT 4")
Try this.