I have two tables: userfollow
`id` int(11) NOT NULL AUTO_INCREMENT,
`theuserid` int(11) NOT NULL,
`follower` int(11) NOT NULL,
`followstatus` int(11) NOT NULL,
users
`users_id` int(11) NOT NULL AUTO_INCREMENT,
`users_username` int(11) NOT NULL,
etc...
When I make this SQL query in phpmyadmin it works as intended:
SELECT *
FROM `userfollow`
LEFT JOIN users on userfollow.theuserid = users.users_id
WHERE users_username = 'hello'
However, in php this does not seem to work:
$stmt = $conn->prepare('SELECT *
FROM userfollow
LEFT JOIN users on userfollow.theuserid = users.users_id
WHERE users_username = ?');
I am able to get the results from the users table in php but not from userfollow table. For example:
$userurl = $_GET['user'];
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$stmt = $conn->prepare('SELECT * FROM userfollow LEFT JOIN users on userfollow.theuserid = users.users_id WHERE users_username = ?');
$stmt->bind_param('s', $userurl);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_array()){
$profilepageusername = $row['users_username'];
$thestatus = $row['followstatus'];
I am able to print out the username of the profile page but followstatus is null.
var_export($thestatus);
returns a null.
It's worth pointing out that if I did the other way around the results would be the same, meaning that the query would return null results from the userfollow table:
SELECT *
FROM `users`
LEFT JOIN userfollow on userfollow.theuserid = users.users_id
WHERE users_username = 'hello';
This does not seem to work either. I've never had to use aliases before in php and to my knowledge the columns arent overwriting eachother or am I wrong? Any tips would be greatful thanks!