How to create dynamic table in php(data is coming from Database-MySql)

Hi every body, i am fresher for php and i need answer for creating dynamic table with php i.e we have more content in our data base(MySql), i need to create table at run time.

any advise would be appreciated

Google for ‘mysql php manual’?
No kidding, you’ll need to start studying some beginner manuals, and the web is full of those. Or buy one of the SP books :smiley:

Then, if you have troubles understanding something, there’ll be lots of people here to help you out. But you have to start studying first, otherwise we’d be writing the whole website for you :wink:

1 Like

Dear tibco29,
I have read your requirements, and before submitting the code I have to know for which specific reason you need dynamic tables. See, dynamic tables are mostly required to store the data from the cache memory to store the transactions of online users. The utility of dynamic tables can also be obtained from static ones, however, you can check the code below:

<?php
include("conn.php");
//$query = "select field1, fieldn from table [where clause][group by clause][order by clause][limit clause]";

$query = "select * from kids";
$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();
}
?>

Let me know whether this is of any use.

1 Like