2016-08-24 25 views
-1

请尝试连接两个表来获取记录,以回显一个表中的记录。当我连接两个表时,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 
       } 
?> 
+0

在查询中删除$ senderid周围的单引号 – jophab

+0

图像没有显示出来! –

+0

一些明智的代码缩进将是一个好主意。它可以帮助我们阅读代码,更重要的是,它可以帮助您**调试您的代码** [快速浏览编码标准](http://www.php-fig.org/psr/psr-2/ )为了您自己的利益。您可能会被要求在几周/几个月内修改此代码 ,最后您会感谢我。 – RiggsFolly

回答

-1

追加与为$ 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 "); 
+0

你不知道PHP双引号文字中的自动$ var扩展吗? – RiggsFolly

+0

那没有显示图像。 –

+0

@RiggsFolly请不要。那是什么? –

-1

双引号加盟申请目的,我认为你需要重新写上以下方式查询CONCAT点:

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

试试这个。

+0

你不知道PHP双引号文字中的自动$ var扩展吗? – RiggsFolly

+0

我改变了我的查询到你的,但它也没有工作。 –

相关问题