Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2012, 12:39 PM
Registered User
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Echo results into a table?

I'm using the following code that does pull the results from a MySQL db, but how can I display the results in a table?

I'm not very familiar with PHP. Any help is greatly appreciated!

<?php
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_logbook ");
//echo "<pre>"; print_r($result); echo "</pre>";
foreach($result as $row)
{
echo $row->ID." ".$row->FDate." ".$row->Flight." ".$row->Departed." ".$row->Arrived." ".$row->Equipment." ".$row->Distance." ".$row->FTime."<br>";
}
?>
 
Old April 30th, 2012, 01:08 AM
prashant2k4
Guest
 
Posts: n/a
Thumbs up Answer

Please try this code:

<?php
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM wp_logbook ");
//echo "<pre>"; print_r($result); echo "</pre>";
?>
<table>
<tr>
<td>ID</td>
<td>Flight Date</td>
<td>Flight</td>
<td>Departed</td>
<td>Arrived</td>
<td>Equipment</td>
<td>Distance</td>
<td>FTime</td>
</tr><?php
foreach($result as $row)
{
echo $row->ID." ".$row->FDate." ".$row->Flight." ".$row->Departed." ".$row->Arrived." ".$row->Equipment." ".$row->Distance." ".$row->FTime."<br>";
?>
<tr>
<td><?php echo $row->ID;?></td>
<td><?php echo $row->FDate;?></td>
<td><?php echo $row->Flight;?></td>
<td><?php echo $row->Departed;?></td>
<td><?php echo $row->Arrived;?></td>
<td><?php echo $row->Equipment;?></td>
<td><?php echo $row->Distance;?></td>
<td><?php echo $row->FTime;?></td>
</tr><?php
}
?>
</table>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems rendering to a table with sorted results jlmacdonald XSLT 6 March 27th, 2008 05:54 PM
Results in line from sam table rodmcleay SQL Language 2 August 2nd, 2007 04:57 AM
Transferring results from a query to another table GujuNilesh SQL Server 2005 1 March 2nd, 2007 02:00 PM
Chapter 8: Results Table not building Steve Rosenthal BOOK: Beginning Access VBA 1 September 7th, 2004 06:11 AM
How to store results of several scripts in table fawadr4656abp Oracle 0 June 13th, 2003 03:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.