So I have 3 tables like so
Table: users
user_id(int) | phone(int)
Table: products
prod_id(int) | prod_info(varchar)
Table: prod_owners
owner_id(int) | user_id | prod_id
I created a function where I can parse in a phone number. It will look up that phone number to get the user_id. The using the user_id it will join the prod_owners table. Then using the prod_id from the prod_owners table, it will join the products table, where the user_id has the same phone number we parsed in.
However, when I run the function, I get no errors, or anything. Its just blank. I know the function works because when I do SELECT * FROM users. It works. I also know there is data with in the table (the data I want it to output).
function get_info($stmt, $phone) {
$userID = search_user($stmt, $phone); // I feel I don't even need this
// I feel I can put this in the
// sql statement itself. But I am
// unsure how
if ($userID == false) {
return "Sorry, user not found";
}
$sql = "SELECT u.user_id, o.prod_info
FROM users u
JOIN prod_owners o
USING user_id
JOIN products
USING o.prod_id
WHERE u.phone = ?";
if(!mysqli_stmt_prepare($stmt, $sql)) {
return false;
} else {
mysqli_stmt_bind_param($stmt, "i", $userID);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while($row = mysqli_fetch_assoc($result)) {
echo $row['prod_info'] . "<br>";
}
}
}