dongyangben6144 2017-03-22 01:38
浏览 22

UNION在php中搜索多个表

Hello genius programmers can help me to figure out my error in UNION search error in "mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean".

<?php 
        if(isset($_GET['search'])) {
            $search_key = $_GET['search'];
            $sql_search = "(SELECT lastname, firstname, 'organization_member' as type FROM org_member WHERE lastname LIKE '%" . 
                            $search_key . "%' OR firstname LIKE '%" . $search_key ."%')
                            UNION
                            (SELECT title, 'fedetated_member' as type FROM fedetated_members WHERE title LIKE '%" . 
                            $search_key . "%')";

            $query_search = mysqli_query($CONNECTION, $sql_search);
        }
    ?>

    <div class='body_wrap'>
        <div class='inner_wrap'>
            <span class='text_black_big'>SEARCH RESULT FOR: <?php echo $_GET['search']; ?></span>
                <table>
                <?php while($row_search = mysqli_fetch_array($query_search)) { ?>
                    <tr>
                        <td><br><?php echo $row_search['organization_member'] ?><br><br><?php echo $row_search['fedetated_member'] ?><br></td>
                    </tr>
                <?php } ?>
                </table>
        </div>
    </div>
  • 写回答

2条回答 默认 最新

  • dqeq885710 2017-03-22 01:48
    关注

    https://msdn.microsoft.com/en-us/library/ms180026.aspx

    Combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The UNION operation is different from using joins that combine columns from two tables. The following are basic rules for combining the result sets of two queries by using UNION: The number and the order of the columns must be the same in all queries. The data types must be compatible.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线