I have a prepared statement (select with joins) inside my php that seems to be assigning values to all but one of its variables:
$dbRating = "x";
$dbFavDate = "x";
if($stmt = $dbcon->prepare("
SELECT i.*, u.username, r.rating, f.date_favorited
FROM image i
INNER JOIN user u ON u.uid = ?
LEFT JOIN rating r ON r.iid = ? AND r.uid = ?
LEFT JOIN favorite f ON f.iid = ? AND f.uid = ?
WHERE i.iid = ?")) {
$stmt->bind_param("iiiiii", $qImageOwner, $qImageId, $uid, $qImageId, $uid, $qImageId);
$stmt->execute();
$stmt->bind_result($dbIid, $dbOwnerUid, $dbTitle, $dbDescription, $dbFilename, $dbCatid, $dbDateCreated, $dbDateModified, $dbOwnerUsername, $dbRating, $dbFavDate);
$stmt->fetch();
$stmt->close();
}
I have put this query into phpmyadmin directly and gotten back all expected values, so I know it's not the sql. I am getting all values returned as expected except for the $dbFavDate, for some reason this always displays as 'x' (the initial value I assigned to it before the query), while the $dbRating which is handled the same way returns the expected associated rating value. No errors are produced, it seems that variable is just not being assigned the actual value returned from the query?
Any help would be greatly appreciated. Thanks, TE
Argh! Finally. It was neither a problem with the sql OR php. An if statement in the javascript was using
if (dbFavDate = 'x') {
rather than
if (dbFavDate == 'x') {
(>_<) !! Thanks for the input guys.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.