I'm using the vuejs library and want to get the data from mysql by combining two tables. I can't get data from json when I use INNER JOIN. Could you please review the codes?
Thank you
$list = $db->query("SELECT*FROM table1 as u INNER JOIN table2 as p ON u.id = p.userID WHERE p.contentID = '$cID');
$item = $list->first();
$res = array();
$res[] = $item;
$row['respons'] = $res;
header("Content-type: application/json");
echo json_encode($row);
die();
TABLE 1 Name (Example) : user
id: 1 - username:Serkan
id: 2 - username:Jack
id: 3 - username:Rose
Table 2 Name (Example) : content
id:x - userID: 1 - content: This is mysql content
id:x - userID: 3 - content: new mysql content
You have quite a few syntax and spelling errors, also you should read up more on how sql queries work with php. If your "cID" variable is user input, you should also sanitize this input before sending it to your database server to avoid sql injection attacks.
$list = $db->query("SELECT*FROM table1 as u INNER JOIN table2 as p ON u.id = p.userID WHERE p.contentID = '$cID';");
$res = [];
if ($list ->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
array.push($res, $row['response'])
}
{
header("Content-type: application/json");
echo json_encode($res);
die();