0

如果选择了任一语句并显示它们,如何mysql_fetch_assoc为任一语句排列?select

$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']
4

1 回答 1

1

您可以尝试以下方法。这样,无论来自 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

于 2013-09-11T05:54:28.957 回答