Results 1 to 2 of 2

Thread: display data in tables

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2009
    Posts
    135

    display data in tables

    Hi

    I have a database and i want to display the data from the database to the php page in a tabular from. how do i go about it

    the fields in the database are
    1)mobile_number
    2) cust_name
    3 ) emp_no

    any help would be appriciated

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: display data in tables

    Code:
    <table>
    <thead>
    <tr>
    <td>Mobile Number</td>
    <td>Customer Name</td>
    <td>Employee No.</td>
    </tr>
    </thead>
    <tbody>
    <?php
    //connect and select database
    
    //query for your data
    $sql_result = mysql_query("SELECT * FROM tableName ORDER BY emp_no");
    
    //mysql_fetch_assoc() gets an associative array of the current
    //row in your result set. by putting it in a while loop,
    //it will continue to get each row until the end of the set.
    //on each loop, $sql_row is populated with the array of the
    //current row
    while($sql_row = mysql_fetch_assoc($sql_result)){
      ?>
      <tr>
      <td><?php echo $sql_row["mobile_number"];?></td>
      <td><?php echo $sql_row["cust_name"];?></td>
      <td><?php echo $sql_row["emp_no"];?></td>
      </tr>
      <?php
    }
    ?>
    </tbody>
    </table>
    Ask questions if you don't understand any of it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width