1
<?php

require_once('../lankain.php');

if(isset($_POST['queryString'])) {

    $queryString = $dbc->real_escape_string($_POST['queryString']);

    if(strlen($queryString) >0) {
        //$query = $dbc->query("SELECT subjects FROM subject WHERE subjects LIKE '$queryString%' LIMIT 10");
        $q = "SELECT keyword, col 
                FROM (
                    SELECT tutor_name AS keyword, 'Tutors' col FROM tutors
                    UNION
                    SELECT subjects AS keyword, 'Subject' col FROM subject
                    UNION
                    SELECT city_name AS keyword, 'City' col FROM city
                    UNION
                    SELECT institute_name AS keyword, 'Institute' col FROM institutes
                ) s
              WHERE keyword LIKE '%$queryString%' 
              LIMIT 10";

        $r = mysqli_query ( $dbc, $q);

        if($q) {
        while ($row = mysqli_fetch_array($r, MYSQL_ASSOC)) {

            $col = $row['col'];


        }
        } else {
            echo 'ERROR: There was a problem with the query.';
        }
    } else {

    }
} else {
    echo 'There should be no direct access to this script!';
}

?>

私のクエリは、カテゴリ名を選択せず​​に、科目、チューター名、機関、および都市のみを選択します。ここで、結果セットに従ってカテゴリ名を追加する必要があります..

phpでできることを知ることができますか?

4

1 に答える 1

5

これを試して:

SELECT col, keyword
FROM (SELECT tname AS keyword, 'Tutors' col FROM t
      UNION
      SELECT sname AS keyword, 'Subjects' col FROM sub
      UNION
      SELECT cname AS keyword, 'City' col FROM c
      UNION
      SELECT iname AS keyword, 'Institutes' col FROM i
    ) AS s
WHERE keyword LIKE '%$queryString%' 
LIMIT 10

結果セットにカテゴリをどのようにマップしますか?

于 2012-11-27T04:50:16.313 に答える