Jump to content

Recommended Posts

I am trying to create a table in php that retrieves all the entries from the db, but what should I change to make it work?

 

<?php
include 'cnt.php';
echo "<table>";
$query = mysql_query("SELECT bfn, bln, loan_id, status FROM Loans");
while(list($bfn, $bln, $loan_id, $status) = mysql_fetch_row($query)){
$bor = $bln.", ".$bfn;
echo "<tr>
<td>$bor</td>
<td>$loan_id</td>
<td>$status</td>
</tr>";
}
echo "</table>";
?>

 

When I run it, it return the following:

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/public_html/test/test.php on line 5

 

Link to comment
https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/
Share on other sites

Try this:

 

<?php
include('cnt.php');

$query = mysql_query('SELECT bfn, bln, loan_id, status FROM Loans') or
         die('Error: '.mysql_error());

echo '<table>';
while($row = mysql_fetch_assoc($query)) {
    echo "<tr><td>$bln, $bfn</td><td>$loan_id</td><td>$status</td></tr>";
}
echo '</table>';
?>

Okay, here is the correct one:

 

<?php
include('cnt.php');

$query = mysql_query('SELECT bfn, bln, loan_id, status FROM Loans') or
         die('Error: '.mysql_error());

echo '<table>';
while($row = mysql_fetch_assoc($query)) {
    echo "<tr><td>{$row[bln]}, {$row[bfn]}</td><td>{$row[loan_id]}</td><td>{$row[status]}</td></tr>";
}
echo '</table>';
?>

Ok.  I see the problem.  I have 2 different tables.  Borrowers and Loans.  Borrowers holds the Borrower's personal info.  Name, Address, etc.  Loans holds the info for the loan.  They both have the bor_id field.  Is there some way I can retrieve the following fields from both tables:

 

Borrowers Table - bor_id, bfn, bln

 

Loans Table - bor_id, loan_id, status

 

Keep in mind that some of the borrowers have more than 1 loan.

Ok.  I see the problem.  I have 2 different tables.  Borrowers and Loans.  Borrowers holds the Borrower's personal info.  Name, Address, etc.  Loans holds the info for the loan.  They both have the bor_id field.  Is there some way I can retrieve the following fields from both tables:

 

Borrowers Table - bor_id, bfn, bln

 

Loans Table - bor_id, loan_id, status

 

Keep in mind that some of the borrowers have more than 1 loan.

 

What?

 

If your loading two tables at once, use INNER JOIN.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.