Javascript中带有搜索引擎的内部联接表不会生成对数据库的查询

Javascript中带有搜索引擎的内部联接表不会生成对数据库的查询,javascript,php,mysql,sql,sql-server,Javascript,Php,Mysql,Sql,Sql Server,我让搜索表单从MySQL中的多个其他表中查询一个内部联接表。当我在PHPMyAdmin中运行SQL时,我正在使用一个带有Xampp/Apache的本地intranet,它运行得非常完美,生成的结果完全符合我希望在我的网站上显示的结果 我的数据库名是:loodt 我的桌子是:ee,呃,aa,理算师和律师。 我在ee表上有其他表的外键ee.er_id=er.id等 然而,当我尝试在我的网站上运行搜索时,它会弹出一个错误,说 无法查询数据库中的搜索结果,MYSQL错误表“loodt.ee a”不存在。

我让搜索表单从MySQL中的多个其他表中查询一个内部联接表。当我在PHPMyAdmin中运行SQL时,我正在使用一个带有Xampp/Apache的本地intranet,它运行得非常完美,生成的结果完全符合我希望在我的网站上显示的结果

我的数据库名是:loodt 我的桌子是:ee,呃,aa,理算师和律师。 我在ee表上有其他表的外键ee.er_id=er.id等

然而,当我尝试在我的网站上运行搜索时,它会弹出一个错误,说 无法查询数据库中的搜索结果,MYSQL错误表“loodt.ee a”不存在。 所以我试着去掉[下面代码中引用的]A、B、C、D 在几天前我开始修改一个表之前,我已经在使用搜索引擎从一个表中查询结果了,所以我知道它是有效的,这是一个临时表的问题,当然还有我的知识不足

以下是搜索引擎javascript:

上面的javascript文件是从标题中的索引页调用的,不确定这是否重要。这是在上面的javascript代码中调用的search.php文件

>     <?php
    //Prepare an array to hold data we are going to send back to the jQuery
    $data = array(
        'results' => array(),
        'success' => false,
        'error' => '' 
    );
    //Has the text been posted?
    if (isset($_POST['text'])) {
        //Connect to the database


>
$dbhost = 'localhost'; //hostname
$dbuser = 'xxxx'; //database username
$dbpass = 'xxxxx'; //database password
$dbname = 'loodt'; //database name
>
//Create the connection to the mySQL database or catch the exception if there is an error
$db = new mysqli($dbhost, $dbuser, $dbpass);
>
$db->select_db($dbname);
>
if($db->connect_errno > 0){
    die('ERROR! - COULD NOT CONNECT TO mySQL DATABASE: ' . $db->connect_error);
}
>

>       //Escape the text to prevent SQL injection
        $text = $db->real_escape_string($_POST['text']);
        //Run a LIKE query to search for titles that are like the entered text
>
        $q = "SELECT `A.name AS A_name`, `D.name AS D_name`, `A.file_no AS A_file_no`, `A.claim_no AS A_claim_no`, 
`A.adj_no AS A_adj_no`, `F.acronym AS F_acronym`, `A.doi AS A_doi`, `A.opened AS A_opened`, 
`A.status AS A_status`, `A.redwells AS A_redwells`, `C.initials AS C_initials`, `B.name AS B_name`, `E.firm_name AS E_firm_name`
FROM `ee A`
INNER JOIN `adjuster B` ON `A.adjuster_id` = `B.id`
INNER JOIN `attorney C` ON `A.attorney_id` = `C.id`
INNER JOIN `er D` ON `A.er_id` = `D.id`
INNER JOIN `aa E` ON `A.aa_id` = `E.id`
INNER JOIN `wcab F` ON `A.wcab_id` = `F.id`



>
WHERE 

`A_name` LIKE '%{$text}%' OR `A_file_no`  LIKE '%{$text}%' OR `A_claim_no`  LIKE '%{$text}%' OR `A_adj_no`  LIKE '%{$text}%' OR `A_doi`  LIKE '%{$text}%'";;
        $result = $db->query($q);
        //Did the query complete successfully?
        if (!$result) {
            //If not add an error to the data array
            $data['error'] = "Could not query database for search results, MYSQL ERROR: " . $db->error;
        } else {
            //Loop through the results and add to the results array
            while ($row = $result->fetch_assoc()) {
                $data['results'][] = array(
                    'A_name' => $row['A_name'],
                    'D_Name' => $row['D_name'],
                    'A_file_no' => $row['A_file_no'],
                    'A_claim_no' => $row['A_claim_no'],
                    'A_adj_no' => $row['A_adj_no'],
                    'F_acronym' => $row['F_acronym'],
                    'A_doi' => $row['A_doi'],
                    'A_opened' => $row['A_opened'],
                    'A_status' => $row['A_status'],
                    'A_redwells' => $row['A_redwells'],
                    'C_initials' => $row['C_initials'],
                    'B_name' => $row['B_name'],
                    'E_firmname' => $row['E_firmname']

                );
            }
            //Everything went to plan so set success to true
            $data['success'] = true;
        }
    }
    //Set the content type for a json object and ensure charset is UTF-8. NOt utf8 otherwise it will not work in IE (Darn IE! >.<)
    header("Content-Type: application/json; charset=UTF-8");
    //json encode the data and cast to an object so we can reference items like this.id in the javascript instead of this['id'] etc.
    echo json_encode((object)$data);
?>
以下是指向SQl查询图像和列名的链接:


我刚刚编辑了上面的几个简短的词,以注意我正在查询1个内部联接表,而不是一组内部联接表。背景标记都是错误的。是'a.name AS a_name'真的是列名吗?请参考我刚刚发布的图像的链接。当结果表出现时,这些是列名。好的,我将它们重新命名为,但仍然不起作用,相同的MySQL错误消息显示,表loodt.ee a不存在
>     <?php
    //Prepare an array to hold data we are going to send back to the jQuery
    $data = array(
        'results' => array(),
        'success' => false,
        'error' => '' 
    );
    //Has the text been posted?
    if (isset($_POST['text'])) {
        //Connect to the database


>
$dbhost = 'localhost'; //hostname
$dbuser = 'xxxx'; //database username
$dbpass = 'xxxxx'; //database password
$dbname = 'loodt'; //database name
>
//Create the connection to the mySQL database or catch the exception if there is an error
$db = new mysqli($dbhost, $dbuser, $dbpass);
>
$db->select_db($dbname);
>
if($db->connect_errno > 0){
    die('ERROR! - COULD NOT CONNECT TO mySQL DATABASE: ' . $db->connect_error);
}
>

>       //Escape the text to prevent SQL injection
        $text = $db->real_escape_string($_POST['text']);
        //Run a LIKE query to search for titles that are like the entered text
>
        $q = "SELECT `A.name AS A_name`, `D.name AS D_name`, `A.file_no AS A_file_no`, `A.claim_no AS A_claim_no`, 
`A.adj_no AS A_adj_no`, `F.acronym AS F_acronym`, `A.doi AS A_doi`, `A.opened AS A_opened`, 
`A.status AS A_status`, `A.redwells AS A_redwells`, `C.initials AS C_initials`, `B.name AS B_name`, `E.firm_name AS E_firm_name`
FROM `ee A`
INNER JOIN `adjuster B` ON `A.adjuster_id` = `B.id`
INNER JOIN `attorney C` ON `A.attorney_id` = `C.id`
INNER JOIN `er D` ON `A.er_id` = `D.id`
INNER JOIN `aa E` ON `A.aa_id` = `E.id`
INNER JOIN `wcab F` ON `A.wcab_id` = `F.id`



>
WHERE 

`A_name` LIKE '%{$text}%' OR `A_file_no`  LIKE '%{$text}%' OR `A_claim_no`  LIKE '%{$text}%' OR `A_adj_no`  LIKE '%{$text}%' OR `A_doi`  LIKE '%{$text}%'";;
        $result = $db->query($q);
        //Did the query complete successfully?
        if (!$result) {
            //If not add an error to the data array
            $data['error'] = "Could not query database for search results, MYSQL ERROR: " . $db->error;
        } else {
            //Loop through the results and add to the results array
            while ($row = $result->fetch_assoc()) {
                $data['results'][] = array(
                    'A_name' => $row['A_name'],
                    'D_Name' => $row['D_name'],
                    'A_file_no' => $row['A_file_no'],
                    'A_claim_no' => $row['A_claim_no'],
                    'A_adj_no' => $row['A_adj_no'],
                    'F_acronym' => $row['F_acronym'],
                    'A_doi' => $row['A_doi'],
                    'A_opened' => $row['A_opened'],
                    'A_status' => $row['A_status'],
                    'A_redwells' => $row['A_redwells'],
                    'C_initials' => $row['C_initials'],
                    'B_name' => $row['B_name'],
                    'E_firmname' => $row['E_firmname']

                );
            }
            //Everything went to plan so set success to true
            $data['success'] = true;
        }
    }
    //Set the content type for a json object and ensure charset is UTF-8. NOt utf8 otherwise it will not work in IE (Darn IE! >.<)
    header("Content-Type: application/json; charset=UTF-8");
    //json encode the data and cast to an object so we can reference items like this.id in the javascript instead of this['id'] etc.
    echo json_encode((object)$data);
?>