gpt4 book ai didi

mysql - 2. 如何从mysql表中获取数据

转载 作者:行者123 更新时间:2023-11-29 12:55:11 26 4
gpt4 key购买 nike

这是我的代码,我需要来自 2 个表的数据。第一个:ps_customer(id_customer,firstname,lastname,email) 第二个:ps_adress(phone_mobile)

我收到错误:

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

这是我的代码:

<?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>';
?>

最佳答案

首先,您必须在两个表之间建立关系,例如通过一个关键字段,然后您应该连接这些表,然后您可以继续进行 SELECT 查询。

关于mysql - 2. 如何从mysql表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24164979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com