refiking Posted January 3, 2008 Share Posted January 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/ Share on other sites More sharing options...
Grant Holmes Posted January 3, 2008 Share Posted January 3, 2008 I'll admit to being a newbie, but willing to help. I think you're going to need to set up a loop to go through ALL of your records, THEN show them. As I see it, your current structure would only show one record. Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429642 Share on other sites More sharing options...
phpSensei Posted January 3, 2008 Share Posted January 3, 2008 if its a invalid arguement, it means the query is wrong. try $query = mysql_query("SELECT bfn, bln, loan_id, status FROM Loans") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429643 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429653 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 Opps, forgot something, Let me fix it, Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429655 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429661 Share on other sites More sharing options...
refiking Posted January 3, 2008 Author Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429663 Share on other sites More sharing options...
phpSensei Posted January 3, 2008 Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429666 Share on other sites More sharing options...
refiking Posted January 3, 2008 Author Share Posted January 3, 2008 I just added the needed fields to the other table and used one table. Worked perfectly. Now, I just need to figure out how to insert the lines to divide the columns. Quote Link to comment https://forums.phpfreaks.com/topic/84351-solved-trying-to-create-table/#findComment-429682 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.