当我连接两个表时,Sql无法获取列的记录

时间:2016-08-24 12:44:48

标签: php html mysql echo jointable

请尝试连接两个表以获取记录回显一个表中的记录。

第一个是表'客户'第二个是表'受益人1'。

何时,我尝试加入表格,然后才获取记录 (i.e receiver_id and receiver_name)的{​​{1}}但该表格未显示另一个表格中的客户记录(即profile_pictures)。

可能导致这种情况的原因,我已经尝试了所有我能想到的代码!

'beneficiary1'

FOR BENEFICIARY!

<?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 CUSTOMER

<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
                }
?>

2 个答案:

答案 0 :(得分:-1)

附加带有双引号的concat dot 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 ");

答案 1 :(得分:-1)

为了加入目的,我认为您需要按以下方式重新编写查询:

$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")

试试这个。