<?phpdefine('DB_HOST', 'localhost');define('DB_USER', 'root');define('DB_PASS', '');define('DB_NAME', 'websitefinal');//connecting to database and getting the connection object$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);//Checking if any error occured while connectingif (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); die();} else {}if ($_SERVER['REQUEST_METHOD'] == 'GET') { $id = $_POST['user_id'] ?? ''; $query = "SELECT UL.* FROM users UL INNER JOIN active_crew L JOIN search SL ON L.user_id = UL.user_id AND L.search_id = SL.search_id"; $sql = mysqli_query($conn, $query); $result2 = array(); while ($row = mysqli_fetch_array($sql)) { array_push($result2, array( 'user_id' => $row[0], 'name_full' => $row[1], 'Propic' => $row[4])); } echo json_encode($result2); mysqli_close($conn);}我正在嘗試檢索在特定搜索“搜索表”中值班的活躍船員表中的用戶“用戶表”的信息,但我沒(méi)有收到任何信息我想從“user_id”主鍵和外鍵檢索數(shù)據(jù)的用戶表crew 表只有 2 列 search_id 和 user_id 都是外鍵應(yīng)具有職責(zé)描述“search_id”主鍵和外鍵的搜索表鍵關(guān)系對(duì)所有列都有效 search_id.crew with search_id.search user_id.crew with user_id.user
1 回答

手掌心
TA貢獻(xiàn)1942條經(jīng)驗(yàn) 獲得超3個(gè)贊
ON您必須在each 的子句中設(shè)置每個(gè)連接的條件JOIN,而不是在 last 中設(shè)置所有連接的條件ON:
SELECT UL.*
FROM users UL
INNER JOIN active_crew L ON L.user_id = UL.user_id
INNER JOIN search SL ON L.search_id = SL.search_id
- 1 回答
- 0 關(guān)注
- 112 瀏覽
添加回答
舉報(bào)
0/150
提交
取消