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
483 Guests, 101 Users ckryptix, Ios, viper0i0, Diznablo, rabbidmind, asapong, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nicid1, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019, Jakabo |
| |
|
|
|
|
|