Dyanmic Report in PHP


Dynamic report in PHP



  • ·         Suppose you have only the name of the database and table, you don’t know the field name of your table and you want to fetch the data from the table.

  • ·         In this situation we are going to teach how to fetch data from database.

  • ·         Open your favorite text editor and type following code.

  • ·         Here I have database name cat and table name product.

  • ·         But I don’t know the field name of product table.

<?php
            $con=mysql_connect("localhost","root","") or die("can't connect");
            mysql_select_db("cat");
            $qu=mysql_query("select * from product");       //query to product table.
            $c=mysql_num_fields($qu);      // This function return the number of row in your table.
            echo "<table border=1><tr>";
            for($i=0;$i<$c;$i++)
            {
            echo "<td>".mysql_field_name($qu,$i)."</td>"; //This function return the name of rows
            }
            echo '</tr>';
           
            while($row=mysql_fetch_array($qu))
            {
                        echo "<tr>";                
                 for($i=0;$i<$c;$i++)
                   {
            echo "<td>".$row[mysql_field_name($qu,$i)]."</td>"; //Here we are display it

                   }
                                   
                        echo '</tr>';
            }
            echo "</table>";
            mysql_close($con);
?>


  • ·         Save this file as index.php and run it.
 

  • ·          It will look like this.
  • ·         Our dynamic report in php will now over here have fun with PHP.
 
 



Post a Comment

Previous Post Next Post