访问SQL对象内部联接的数据

时间:2015-12-22 22:05:42

标签: sql join sqlobject

我正在尝试使用此内部联接来显示输出标题和日期。仅返回提供对象详细信息的sql对象。这是结果。我可以访问num_rows,但只是给我int(11)记录的数量,不知道如何访问字段中的信息。 这是结果。 object(mysqli_result)#6(5){[“current_field”] => int(0)[“field_count”] => int(2)[“lengths”] => NULL [“num_rows”] => int(11)[“type”] => int(0)}

感谢您的帮助。

$sql  = "SELECT  title, artist_name"; 
$sql .= " FROM follows";
$sql .= " INNER JOIN artworks";
$sql .= " ON follows.user_id_followed = artworks.artist_id";
$sql .= " AND follows.user_id_follower='12'";

$result_set = $database->query($sql);

echo var_dump($result_set);

1 个答案:

答案 0 :(得分:0)

你需要一个WHERE

$sql  = "SELECT  title, artist_name"; 
$sql .= " FROM follows";
$sql .= " INNER JOIN artworks";
$sql .= " ON follows.user_id_followed = artworks.artist_id";
$sql .= " WHERE follows.user_id_follower='12'";

您可能也希望LEFT JOIN不是INNER JOIN`