Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Show mySQL table as HTML Jump to:  
Category: >> PHP Code >> Show mySQL table as HTML Bookmark and Share

<< lastnext >>

Snippet Name: Show mySQL table as HTML

Description: This example use mySQL functions from PHP to display a full mySQL table (every column and every row) as HTML.

Comment: (none)

Language: PHP, MYSQL
Highlight Mode: PHP
Last Modified: February 28th, 2009

<?PHP
 
$table = 'spheres';
 
IF (!MYSQL_CONNECT($db_host, $db_user, $db_pwd))
    DIE("Can't connect to database");
 
IF (!MYSQL_SELECT_DB($database)) DIE("Can't select database");
 
// sending query
$result = MYSQL_QUERY("SELECT * FROM {$table}");
IF (!$result) {
    DIE("Query to show fields from table failed");
}
 
$fields_num = MYSQL_NUM_FIELDS($result);
 
ECHO "<h1>Table: {$table}</h1>";
ECHO "<table border='1'><tr>";
// printing table headers
FOR($i=0; $i<$fields_num; $i++)
{
    $field = MYSQL_FETCH_FIELD($result);
    ECHO "<td>{$field->name}</td>";
}
ECHO "</tr>\n";
// printing table rows
WHILE($row = MYSQL_FETCH_ROW($result))
{
    ECHO "<tr>";
 
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    FOREACH($row AS $cell)
        ECHO "<td>$cell</td>";
 
    ECHO "</tr>\n";
}
MYSQL_FREE_RESULT($result);
 
?>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 61 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?