Advertisement
Guest User

Untitled

a guest
May 29th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?PHP
  2. //here I define the names of the fields I am selecting (in the query)
  3. $field_array = array( 'UFName','ULName','UStreet1','UCity');
  4. //standard DB connection
  5. $user_name = "root";
  6. $password = "";
  7. $database = "team3";
  8. $server = "127.0.0.1";
  9.  
  10. $db_handle = mysql_connect($server, $user_name, $password);
  11. $db_found = mysql_select_db($database, $db_handle);
  12.  
  13. if ($db_found) {
  14. //print "Database Found!". "<BR>";
  15. $query = "SELECT * FROM user";
  16. $result = mysql_query($query);
  17. //makes a table from the query results and categorizes by the field names
  18. getTable($result, $field_array);
  19. mysql_close($db_handle);//closes connection to database
  20. }
  21. else {
  22. print "ERROR: Database NOT Found ";
  23. }
  24.  
  25. function getTable($dbResults,$fields){
  26.  
  27. //html for generating table header the way we want
  28. echo "<table class='table'>
  29. <thead>
  30. <tr>
  31. <th>FNAME</th>
  32. <th>LNAME</th>
  33. <th>STREET</th>
  34. <th>CITY</th>
  35. </tr>
  36. </thead>
  37. <tbody>";//html for generating table body
  38. while ( $dbField = mysql_fetch_assoc($dbResults) ) {
  39. echo "<tr>";
  40. for ($i = 0; $i < count($fields); $i++) {
  41. echo '<td>'.$dbField[$fields[$i]].'</td>';
  42. }
  43. echo "</tr>";
  44. }
  45.  
  46. echo "</tbody>
  47. </table>";
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement