gpt4 book ai didi

php - 如何 mysql_fetch_assoc 用于 OR 运算符中给出的两个选择语句以选择任一表

转载 作者:行者123 更新时间:2023-11-29 13:36:04 25 4
gpt4 key购买 nike

如果选择了其中一个,如何为任一select语句创建mysql_fetch_assoc数组并显示它们?

$query1= "SELECT name, email_id,mobile_number from tablename where `user_id='$id'"` 
OR
"SELECT guser_name, guser_email from tablename1 where user_id='$id'";

if($q=mysql_query($query1))
{
$row = mysql_fetch_assoc($q);
$name = $row['guser_name'];
$name1 = $row1['name'];
$mail1 = $row1['email_id'];
$mail= $row['guser_email'] ;
$phone = $row1['mobile_number']

最佳答案

您可以尝试如下所示的操作。这样,无论来自 table1 还是 table2 的所有行都可以使用从 mysql_fetch_assoc 获得的数组中的相同键来访问。

select name1 as name,email1 as email, mobile1 as mobile FROM table1 WHERE id=1
UNION ALL
select name2 as name,email2 as email, '' as mobile FROM table2 WHERE id=1

演示 http://sqlfiddle.com/#!2/9d81c/1

关于php - 如何 mysql_fetch_assoc 用于 OR 运算符中给出的两个选择语句以选择任一表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18732738/

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