Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <?php
- function fetch_records($table_name, $fields){
- $conn = mysql_connect ("host", "user", "pass");
- $select_db = mysql_select_db("base", $conn);
- if(!$conn){
- return "Not able to connect to dabase....";
- }
- $table = "<table align='center' border='1' cellpadding='2' cellspacing='2'>";
- $cols = implode (', ', $fields);
- $sql = "select $cols from $table_name";
- $run = mysql_query($sql);
- if($run){
- if(mysql_num_rows($run) == 0){
- return "Sorry. No records found in the database";
- }
- else {
- while($arr = mysql_fetch_array($run, MYSQL_ASSOC)){
- $table .= "\t\t<tr>\n";
- foreach ($arr as $val_col) {
- $table .= "\t\t\t".'<td>'.$val_col.'</td>'."\n";
- }
- $table .= "\t\t</tr>\n";
- }
- $table .= "</table>";
- return $table;
- }
- mysql_free_result($run);
- }
- echo mysql_error();
- }
- //how to call the function
- $table = "TestsTable";
- $cols = array("ID", "DATE", "NICK", "TESTS", "STATUS", "Comm_Bugs");
- echo fetch_records($table, $cols);
- ?>
- <table align="center">
- <tr>
- <td>
- <FORM METHOD="post">
- <INPUT TYPE="button"
- VALUE="BACK"
- OnClick="history.go( -1 );return true;">
- </FORM>
- </td>
- </tr>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement