dongpu3347 2014-03-11 12:31
浏览 20
已采纳

创建一个完整的mysql搜索查询,搜索多个表

I am trying to search my full website but I'm unsure how to make the query.

    $query = "SELECT * FROM 
game_content,
tech_content,
hint_content
 WHERE 
title LIKE '%".$input."%' 
description LIKE '%".$input."%'";

The tables i want to search are: game_content,tech_content,hint_content & the columns are: title,description each table has these columns

To be honest I'm confused using JOIN i have been getting lots of unexpected results.

  • 写回答

6条回答 默认 最新

  • dousao1175 2014-03-12 13:32
    关注

    After trying out some of your answers i decided to do what Dieter suggested in the comments.

        //set the queries.
    $query[1] = "SELECT * FROM game_content WHERE title LIKE '%".$input."%' OR description LIKE '%".$input."%'";
    $query[2] = "SELECT * FROM hint_content WHERE title LIKE '%".$input."%' OR description LIKE '%".$input."%'";
    $query[3] = "SELECT * FROM tech_content WHERE title LIKE '%".$input."%' OR description LIKE '%".$input."%'";
    
        //loop the queries setting the results
    for ( $i = 1; $i <= 3; $i++ ) {
    
        $result[$i] = mysqli_query( $connection, $query[$i] );
        check_query( $result[$i] );
    
        while( $row = mysqli_fetch_assoc( $result[$i] ) ) {
    
            //display output
        }
    }
    

    It is only a small site so this will suffice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 python摄像头画面无法显示
  • ¥15 关于#3d#的问题:d标定算法(语言-python)
  • ¥15 cve,cnnvd漏洞扫描工具推荐
  • ¥15 图像超分real-esrgan网络自己训练模型遇到问题
  • ¥15 如何构建全国统一的物流管理平台?
  • ¥100 ijkplayer使用AndroidStudio/CMake编译,如何支持 rtsp 直播流?
  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了