This is my first time using an inner join so i'm very confused.
I have two tables.
This is my first table called members
This is my other table called donations. The userID from the members is linked up with the userID on the donations table.
Right so what i'm trying to do is select all of the data from members and from the donations table and assiotate each Id with the donation amount. So what i'm trying to do is echo all of the names along side their donation amount if that makes sense.
This is my code at the moment
$connect - contains my config
//Connection info.
global $connect;
//inner join
$sql = "SELECT members.firstname, members.lastname
FROM members INNER JOIN donations ON members.userID = donations.userID WHERE donations.amount !='' ORDER BY members.userID ASC ";
$result = mysqli_query( $connect, $sql);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$list .= $row["firstname"];
echo $list;
}
I'm getting this error back: mysqli_fetch_array() expects parameter 1 to be mysqli_result boolean
UPDATE: Thanks for all your help, i'm running the SQL query and just getting the first and last name back.
SELECT members.firstname, members.lastname FROM members INNER JOIN donations ON members.userID = donations.userID WHERE donations.amount !='' ORDER BY members.userID ASC
I think i'm doing something wrong here !='' the donation amount is a decimal am i targeting it right?
Replace members.id
by members.userID
in your query.
SELECT members.firstname, members.lastname, donations.amount
FROM members
INNER JOIN donations ON members.userID = donations.userID
WHERE donations.amount != ''
ORDER BY members.userID ASC
As for the SQL error, it's because $result is false
when there's a problem with the query or no result has been found.
mysqli_fetch_array() expects parameter 1 to be mysqli_result boolean
To prevent the error, add a simple if case because your while.
if($result){
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$list .= $row["firstname"];
echo $list;
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments