|
|
The below script shows how to create a dynamic table with headers based on the column names from a query. It automatically creates the table and the correct number of columns
Enjoy
Bastien
| <?php
include("conn.php");
//$query = "select field1, fieldn from table [where clause][group by clause][order by clause][limit clause]";
$query = "select * from kids";
$result = conn($query);
if (($result)||(mysql_errno == 0))
{
echo "<table width='100%'><tr>";
if (mysql_num_rows($result)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
while ($i < mysql_num_fields($result))
{
echo "<th>". mysql_field_name($result, $i) . "</th>";
$i++;
}
echo "</tr>";
//display the data
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center'>". $data . "</td>";
}
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}
echo "</table>";
}else{
echo "Error in running query :". mysql_error();
}
?> | | |
|
| Making a simple Hit-Log using PHP and MySql Categories : PHP, Log Files, Beginner Guides, Databases, MySQL | | | Newbie Notes #10 - Generating drop downs Categories : PHP, MySQL, HTML, Beginner Guides, Databases | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | Convert a File database into MySQL Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Newbie Notes #4 - Trapping dumb MySQL query errors Categories : PHP, Databases, MySQL, Debugging, Beginner Guides | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | for each record, do this to the first record, and do that to any subsequent record Categories : PHP, Databases, MySQL, Beginner Guides | | | mySQL/PHP/search with multientry
form and table output with colored rows Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases | | | Add, Edit /Update & Delete all in one Contact Management Form Categories : PHP, MySQL, Databases, Beginner Guides | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | |
| |
| |
|