2014-06-11 4 views
0

이것은 내 코드이며 2 테이블의 데이터가 필요합니다. 첫 번째 : ps_customer(id_customer,firstname,lastname,email) 및 두 번째 : ps_adress(phone_mobile).2 mysql 테이블에서 데이터를 얻는 방법

<?php 

$conn=mysqli_connect("localhost","login","pass","dbNAME"); 

if (mysqli_connect_errno()) { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$gender = 6; 

$sql = 
    "SELECT 
     ps_customer.id_customer, ps_customer.firstname, ps_customer.lastname, ps_customer.email, ps_adress.phone_mobile 
    FROM 
     ps_customer, ps_adress 
    ps_customer.id_gender = '$gender' "; 

    $rs=mysql_query($sql,$conn) or die(mysql_error()); 
    echo '<table width="100%" border="0" cellspacing="5" cellpadding="5">'; 
    while($result=mysql_fetch_array($rs)) 
    { 
     echo '<tr> 
       <td>'.$result["id_customer"].'</td> 
       <td>'.$result["firstname"].'</td> 
      <td>'.$result["lastname"].'</td> 
       <td>'.$result["email"].'</td> 
       <td>'.$result["phone_mobile"].'</td> 
       </tr>'; 
    } 
    echo '</table>'; 
    ?> 
+0

'ps_customer.id_gender = '$ gender' ";' –

+0

두 테이블이 어떻게 관련되어 있는지 지정하지 않았습니다. (INNER JOIN 또는 OUTTER JOIN) 두 테이블 사이에 일치하는 위치입니다 .. http://www.w3schools.com/sql/sql_join_inner.asp –

+1

실제로 그는','를 사용하여 지정했는데 교차 결합이 발생하지만 원하는 결과는 아닙니다 – xQbert

답변

1

먼저이 키 필드를함으로써 같은 두 테이블 사이의 관계를 확립해야하고 두 번째 당신이 테이블에 가입해야합니다 : 이것은 내 코드

Warning: mysql_query() expects parameter 2 to be resource, object given in /home/domain/public_html/k2.php on line 19

입니다 :

나는 오류가 발생했습니다 그런 다음 SELECT 쿼리로 계속 진행할 수 있습니다.

관련 문제