3. Data show in table

1.Method:
obviously have to put this code in fresh.php. where have your database connect.

 public function getData($table) {
        $query = mysqli_query($this->connect, "SELECT * FROM $table");
        if (mysqli_num_rows($query) > 0) {
            return mysqli_fetch_all($query, MYSQLI_ASSOC);
        } else {
            return "No data available in yor table $table";
        }
    }

2.tabulize_data.php

<?php
include("fresh.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Show Database</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    </head>

    <body>
        <div style="width: 700px; margin: 0 auto">
        <table class="table table-bordered table-hover" style="text-align: center;">
            <tr>
                <td>Id</td>
                <td>Name</td>
                <td>E-mail</td>
                <td>Phone</td>
                <td>Address</td>
            </tr>
            <?php
            $team = $obj->getData("members");
            //print_r($team);
            foreach ($team as $single) {
                extract($single);
                ?>   
                <tr>
                    <td><?php echo $id; ?></td>
                    <td><?php echo $name; ?></td>
                    <td><?php echo $email; ?></td>
                    <td><?php echo $phone; ?></td>
                    <td><?php echo $address; ?></td>
                </tr>
                <?php
            }
            ?>
        </table>
        </div>
    </body>
</html>

Show this like following screenshot:
tabulize-data

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s