EG Information

Main Index
EG Manual
Disclaimer
Legal Information
Hall of Fame
Hall of Shame
Member Rankings
Members List
Meet the Staff

Training Missions

Read Me First New
Basic Skills
Realistic Scenarios
Cryptography
Software Cracking
Linux ELF Binary Cracking
Logical Thinking
Programming
Captcha Cracking New
Patching
Steganography
Deface This Wall
/dev/null
/dev/urandom
/dev/extra New

Knowledge Bank

Discussion Forums
Enigma Chat New
RSS Feeds RSS
Articles / Tutorials
Videos
Online EG MP3 Player Radio
Enigma Zine
Downloads
Tools New

Code Resources

Submit Code
Ajax
ASM
Bash
C
CPP
Csharp
Delphi
Haskell
Java
Javascript
Jython
Lisp
mIRC
MySQL
Perl
PHP
Python
QBASIC
VisualBasic

Hakipedia: An open collaborative for all your information security needs.

The Urinal

Click Here To Vote For EG!

Has Enigma Group Helped You? Then Help Us By Advertising For Us. Place One Of The Following Images On Your Site.

enigma group

enigma group

enigma group

enigma group

Enigma Group's Code Bank


SQL Table to HTML Table Function

By: Teksaid  -  Date Submitted: 2008-11-20 03:23:51

  1. <?php
  2. /******************
  3. * Purpose: Function used to take all the data from a mySQL table
  4. * and create a HTML table display the information .
  5. * Authoer: Teksaid
  6. *******************/
  7.  
  8. // Parameters: mySQLi Connection Object and name of table to display
  9. function htmlTable($connObj, $tableName) {
  10.  
  11. // Query to grab all the table DATA
  12. $tableQuery = "SELECT * FROM " . $tableName;
  13. // Store the results of the query
  14. $tableResults = $connObj->query($tableQuery) or die($connObj->error);
  15.  
  16. // Grab all the column names for the column headers of the HTML table
  17. $colNames = $tableResults->fetch_fields();
  18. echo " <table id='{$tableName}' class='dataTable'>
  19. <tr colspan='2'>";
  20. // Loop through columns names to create column headers
  21. foreach($colNames as $val) {
  22. echo "<td>" .$val->name. "</td>";
  23. }
  24. echo " </tr>";
  25.  
  26. // Put results into an array and loop through until the end of the array
  27. while($tableArray = $tableResults->fetch_assoc()) {
  28. echo "<tr>";
  29. // Loop through columns names to grab each columns corresponding data from results array
  30. foreach($colNames as $val) {
  31. echo "<td>" .$tableArray[$val->name]. "</td>";
  32. }
  33. echo "</tr>";
  34. }
  35. }
  36.  
  37. //////////////////////// EXAMPLE //////////////////////
  38.  
  39. // Creating connection object with mySQL informatoin
  40. $connObj = new mysqli('localhost', 'user', 'pass', 'database');
  41.  
  42. // Calling the output function to display the HTML table
  43. // for the table users from the database in the connection object.
  44. htmlTable($connObj, 'users');
  45.  
  46. ///////////////////////////////////////////////////////
  47. ?>
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