I want to select data from one table that matches certain conditions, and then select data from another table based on conditions of the data I just selected, and be able to view the selections from both tables. I attempted this with a nested select:
$query =
"
SELECT
`url`, `userID`, `likes`, `time`, `latitude`, `longitude`, `distance `,
(SELECT `up` from userHistory WHERE userHistory.url = photoList.url AND userHistory.userID = photoList.userID)
FROM
photoList
WHERE
`valid` = '1' AND `time` > '$validTime' AND `likes` > '-6'
HAVING
`distance` < '1'
ORDER BY
`time` DESC
LIMIT
'0' , '200'";
Basically I want to select an object in the photoList... and then do a select into userHistory matching the url and userID in the selected photoList row. I want to select both of these so that when I loop through in PHP, I could do the following:
while ($row = $result->fetch_assoc()){
$storeObjects[] = array("url" => $row["url"], "userID" => $row["userID"],
"latitude" => $row["latitude"], "longitude" => $row["longitude"],
"likes" => $row["likes"],
"time" => $row["time"], "distance" => $row["distance"],
"userLiked" => $row["up"]); //$row["up"] is ALWAYS NULL
}
In the above loop, $row["up"] is always NULL, while the other categories in the row are the expected values. I am wondering if $row["up"] is even the correct way to access the data selected by the subquery.