PHP Help Needed.

Emmanuel A

Junior Member
Joined
Feb 19, 2018
Messages
118
Reaction score
47
Actually am not a pro in PHP and at times i run into a some crazy issue i do find hard to get a solution. here is my code
HTML:
$query = ("SELECT users.id, users.fname, users.lname, transfers.sender_id, transfers.beneficiary_id, transfers.amount, transfers.date_posted from transfers INNER JOIN users ON users.id=transfers.sender_id WHERE users.id='".$id."' ORDER BY transfers.date_posted DESC ");


Code:
<?php $i=1; while($row = $result->fetch_assoc()){ ?>
    <tr>
        <td><?= $i++ ?></td>
        <td><?= $row['fname'].' '.$row['lname'] ?></td>
        <td><?= $row['beneficiary_id'] ?></td>
        <td><?= $row['amount'] ?></td>
        <td><?= $row['date_posted'] ?></td>
    </tr>
<?php } ?>

"Beneficiary Name is in the Users Table."
"Beneficiary ID is from the transfer Table"
My problem is, i don't want to output beneficiary ID but instead output the Beneficiary name.

Thanks in advance....
 
Last edited:
F56fc6E.png(General)
 
And where is that 'Beneficiary name' you are talking about in your query? I only see variable transfers.beneficiary_id being pulled...
 
And where is that 'Beneficiary name' you are talking about in your query? I only see variable transfers.beneficiary_id being pulled...
Beneficiary Name is in the Users Table.
 
Your db can be hacked anytime. #JustSaying

ALWAYS, ALWAYS parameterize your SQL queries.
 
I think you need to update your query, you aren't asking this from the DB yet. Remember that you are using SELECT > specific values.. not SELECT ALL. So add that value to the selected query variables.
 
No way am gonna try that shit. Drop what!!!!!!
Well, your user might. That's why..

On topic, you are probably looking for LEFT JOIN (or JOIN in general) ON the beneficiary table. For example:

SELECT t.a,t.b, b.name FROM transfer t LEFT JOIN beneficiary b ON b.id = t.something

b.name is the column you are looking for.
 
$query = ("SELECT users.id, users.fname, users.lname, transfers.sender_id, transfers.beneficiary_id, transfers.beneficiary_name, transfers.amount, transfers.date_posted from transfers INNER JOIN users ON users.id=transfers.sender_id WHERE users.id='".$id."' ORDER BY transfers.date_posted DESC ");


<?php $i=1; while($row = $result->fetch_assoc()){ ?>
<tr>
<td><?= $i++ ?></td>
<td><?= $row['fname'].' '.$row['lname'] ?></td>
<td><?= $row['beneficiary_name'] ?></td>
<td><?= $row['amount'] ?></td>
<td><?= $row['date_posted'] ?></td>
</tr>
<?php } ?>


PS: replace "beneficiary_name" with the column name, I don;'t know if it's right
 
Back
Top