Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- //here I define the names of the fields I am selecting (in the query)
- $field_array = array( 'UFName','ULName','UStreet1','UCity');
- //standard DB connection
- $user_name = "root";
- $password = "";
- $database = "team3";
- $server = "127.0.0.1";
- $db_handle = mysql_connect($server, $user_name, $password);
- $db_found = mysql_select_db($database, $db_handle);
- if ($db_found) {
- //print "Database Found!". "<BR>";
- $query = "SELECT * FROM user";
- $result = mysql_query($query);
- //makes a table from the query results and categorizes by the field names
- getTable($result, $field_array);
- mysql_close($db_handle);//closes connection to database
- }
- else {
- print "ERROR: Database NOT Found ";
- }
- function getTable($dbResults,$fields){
- //html for generating table header the way we want
- echo "<table class='table'>
- <thead>
- <tr>
- <th>FNAME</th>
- <th>LNAME</th>
- <th>STREET</th>
- <th>CITY</th>
- </tr>
- </thead>
- <tbody>";//html for generating table body
- while ( $dbField = mysql_fetch_assoc($dbResults) ) {
- echo "<tr>";
- for ($i = 0; $i < count($fields); $i++) {
- echo '<td>'.$dbField[$fields[$i]].'</td>';
- }
- echo "</tr>";
- }
- echo "</tbody>
- </table>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement