Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Query not selecting data based on WHERE value

Tags:

sql

php

mysql

I'm trying to return all records from my database where the userID is equal to the logged in user.

I have the following only for some reason its not returning anything, can anybody see any obvious errors?

<?php 
$interestsquery  = "SELECT * 
                      FROM user_interests 
                     WHERE user_id = $usersClass->userID()";
$result = mysql_query($interestsquery);

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "{$row['interest']}";
} 
?>
like image 346
Liam Avatar asked Sep 11 '26 04:09

Liam


1 Answers

Unfortunately, you can't call functions and have them parsed that way. You'll either need to concatenate manually, or set a variable and parse that.

Try this:

"SELECT * FROM user_interests WHERE user_id = " . $usersClass->userID();

Or this:

$uid = $usersClass->userID();
"SELECT * FROM user_interests WHERE user_id = $uid";
like image 196
cwallenpoole Avatar answered Sep 13 '26 18:09

cwallenpoole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!