dousheyan0375 2013-09-11 04:32
浏览 70
已采纳

如何在两个select语句中使用mysql_fetch_assoc,这个语句在OR运算符中给出,以选择表格表格

How to mysql_fetch_assoc array for either of select statement if either one is selected and display them ?

$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']
  • 写回答

1条回答 默认 最新

  • dougengqiu8031 2013-09-11 05:54
    关注

    You can try something like below. This way, all rows whether coming from table1 or table2 can be accessed using same key in array obtained from 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 
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度