我有以下代碼選擇2個不同的表,但相關數據
<?php
require_once('db_connection.php');
$return_arr = array();
$param = $_GET["term"];
$query = "SELECT *
FROM exp_weblog_data,exp_weblog_titles WHERE field_id_5
LIKE '%". $param ."%'
LIMIT 50";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
/* Retrieve and store in array the results of the query.*/
while ($row = $result->fetch_assoc()) {
$row_array['jItemCode'] = $row['field_id_5'];
$row_array['jItemDesc'] = $row['title'];
/* $row_array['jItemWholesale'] = $row['itemWholesale'];
$row_array['jItemRetail'] = $row['itemRetail'];
$row_array['jItemPrice'] = $row['itemPrice'];
$row_array['jQtyOnHand'] = $row['qtyOnHand'];*/
array_push($return_arr, $row_array);
}
$result->free_result();
$mysqli->close();
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
我有兩個表。 「exp_weblog_data」和「exp_weblog_titles」。每個表都有「entry_id」。當我使用「exp_weblog_data」中的「field_id_5」啓動自動提示時,我需要從「exp_weblog_titles」表中提取附加信息。
這是用於自動完成查詢的。我需要從相同的數據庫中的另一個表中的「標題」拉相關數據可以請別人幫助我知道問題在於我的查詢,但我已經嘗試了JOINS和UNION和LEFT JOINS的各種語法你有什麼。有人能幫我嗎
就我個人而言,[當談到連接時,我總是要服從Atwood先生](http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html) –
請解釋你的表格結構 – arilia
真的不能幫助你,除非我們知道表格的結構:什麼鍵與它們相關,以及哪些表格包含'field_id_5'和'title'例如。 –