来自2表的mysql数据

Yes, now I know about JOIN, but still didn't solve this problem.

$gender = 6;

$result = mysqli_query($con,"SELECT * FROM ps_customer c LEFT JOIN ps_adress a ON a.customer_id=c.customer_id WHERE c.id_gender='$gender'");

var_dump($result);

mysqli_close($con);

This is my code, but result: false

I tried var_dump to check why I cant print my data.

Is this data print correct for my code?

 echo "<h1>People</h1>";
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Lastname</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
</tr>";



$result = mysql_query($query) or die(mysql_error());
echo var_dump($result);
while($row = mysql_fetch_array($result)){
  echo "<tr>";
  echo "<td>" . $row['id_customer'] . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['company'] . "</td>";
  echo "<td>" . $row['mobile_phone'] . "</td>";
  echo "</tr>";
}

Simple join will work.

SELECT *
FROM ps_customer c
    LEFT JOIN ps_address a ON a.customer_id=c.customer_id
WHERE c.id_gender = '$gender'
SELECT *
FROM adress a
INNER JOIN customer c ON a.customer_id = c.id
WHERE c.id_gender = $gender

You need a LEFT JOIN (in case of customers having no adress record). Asuming both tables has the same column name "customer_id" to identify the customer, you can use:

SELECT ps_customer.name,
       ps_customer.lastname,
       ps_customer.company,
       ps_address.phone,
       ps_address.mobile
FROM ps_customer
LEFT JOIN ps_address ON ps_address.customer_id = ps_customer.customer_id
WHERE ps_customer.id_gender = '$gender'

But be carefully here. If there are multiple adress-records per one customer possible, you'll get multiple rows containing the same customer data for each adress record. If this is the case, you need a more sophisticated query :)

Your query should be

"select cus.name, cus.lastname, cus.company from ps_customer cus, ps_address add where id_gender='".$gender."' and cus.customer_id=add.customer_id"