Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2008
    Posts
    6

    Question Unanswered: create dynamic table with php for web

    Hello,
    Can somebody help me out with this?
    I have previously done this in asp. I need to do it in php.

    I have some mdb tables that I need to print on screen (through a dynamic web page).
    the table dimensions vary. I can connect to the table without a problem (odbc).

    I need some code to structure the table from the data inside the table.

    for the three columns, to create three columns (or five if there are five),
    for the column headers to use the column names (as used inside the dbtable),
    and have lines as much as there is data (10, 20 maybe).

    the asp code I wrote a while back is of no use for the apache server.

  2. #2
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    PHP Code:
    <?php
    include("conn.php");
    $query "
    select col1,
       col2,
       col3
    FROM
       yourTable
    WHERE
       something..."
    ;

    $result conn($query);
    if ((
    $result)||(mysql_errno == 0))
    {
      echo 
    "<table width='100%'><tr>";
      if (
    mysql_num_rows($result)>0)
      {
              
    //loop thru the field names to print the correct headers
              
    $i 0;
              while (
    $i mysql_num_fields($result))
              {
           echo 
    "<th>"mysql_field_name($result$i) . "</th>";
           
    $i++;
        }
        echo 
    "</tr>";
       
        
    //display the data
        
    while ($rows mysql_fetch_array($result,MYSQL_ASSOC))
        {
          echo 
    "<tr>";
          foreach (
    $rows as $data)
          {
            echo 
    "<td align='center'>"$data "</td>";
          }
        }
      }else{
        echo 
    "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
      }
      echo 
    "</table>";
    }else{
      echo 
    "Error in running query :"mysql_error();
    }
    ?>
    This should get you going in the right direction. Of course you'll need to interchange the mysql functions for M$ functions throughout the script.

Posting Permissions

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