EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
SQL Table to HTML Table FunctionBy: Teksaid - Date Submitted: 2008-11-20 03:23:51 <?php /****************** * Purpose: Function used to take all the data from a mySQL table * and create a HTML table display the information . * Authoer: Teksaid *******************/ // Parameters: mySQLi Connection Object and name of table to display function htmlTable($connObj, $tableName) { // Query to grab all the table DATA $tableQuery = "SELECT * FROM " . $tableName; // Store the results of the query $tableResults = $connObj->query($tableQuery) or die($connObj->error); // Grab all the column names for the column headers of the HTML table $colNames = $tableResults->fetch_fields(); echo " <table id='{$tableName}' class='dataTable'> <tr colspan='2'>"; // Loop through columns names to create column headers echo "<td>" .$val->name. "</td>"; } // Put results into an array and loop through until the end of the array while($tableArray = $tableResults->fetch_assoc()) { // Loop through columns names to grab each columns corresponding data from results array echo "<td>" .$tableArray[$val->name]. "</td>"; } } } //////////////////////// EXAMPLE ////////////////////// // Creating connection object with mySQL informatoin $connObj = new mysqli('localhost', 'user', 'pass', 'database'); // Calling the output function to display the HTML table // for the table users from the database in the connection object. htmlTable($connObj, 'users'); /////////////////////////////////////////////////////// ?>
|
| Return to
php category list |
|
|
Who's Online
413 Guests, 92 Users Ausome1, hemiptera, zofy, sabre725, chrbarrol, dark_void, towncrown, EngGi235, blink_212, klesco, vapour, _InSane_, LordHelmet, BnE, N4g4c3N, ThaKeeper, th3punish3r, locust, c0re, iwanlearn, Anderl, ghostraider100, Ghostrider, eliking510, harsha2hack, NotMyOwn, Calumoo, MajorDeath, Rex_Mundi, bhoang93, r!v3rTw!ggz, jarlskov, invas10n, snozzberries, Nusquam-Redono-Sapientia, data, zeth, psychomarine, yuka, DnA-Ender, 454447415244, Ultraminor, T-Metal, antibubbles, raven001, aVoid, Psiber_Syn, sirEgghead, Protagoras, niggletandco, Vahakn, Chaplin, BinaryShinigami, zoegeorgica, hacker807, Red_beard, eviscerator, TheFender, InjectioN, totalnoob, Posix, obrigadoo, cul8er, Mcasdf, teehee, Ops, Protest123, Blizer, gabel, Marian, Edika, Nasrudin, dochaley, TheRetech, j0sh, kcaz, cool.nik, Sand, SaMTHG, fawk3s, rajabaja, avalor, hettoo, mat_2010, barbseven, daandeveloper33, tommy1092, Likantrop7, sajan619, Knuppel, Distorted, Bloodmaster25 |
| |
|
|
|
|
|