Wednesday, 30 November 2011

PHP: data grid view

Lets demonstrate how to show data in data grid view using php.
When we are working on website, one of the most important things is to show the data in brief and in a nice way
To do that combining HTML tags along with php.
Now lets see small example


The source code of above grid is as shown below (click on the pic and zoom it in).

<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tR style="background-color:#CCCCCC">
    <td width="112" align="left" style="border-bottom:1px solid #000000">
      <span style="color:#003663; font-size:13px">&nbsp;Author &nbsp;</span>
    </td>
    <td width="80" align="left" style="border-bottom:1px solid #000000">
      <span style="color:#003663; font-size:13px">Number &nbsp;</span>
    </td>
    <td width="35" align="center" style="border-bottom:1px solid #000000">
      <span style="color:#003663;font-size:13px"> &nbsp;Class</span>
    </td>
  </tR>
  <?php $q_count = mysql_query("select * from tableName where user_id='17'") or die(mysql_error());
 if(mysql_num_rows($q_count)>0)
 {
 while($r_count = mysql_fetch_array($q_count))
 {
 echo '<tr>
       <td align=left >';
  echo "&nbsp; ".$r_count['fieldName1'];
 echo '</td>
       <td align=left>';
  echo $r_count['fieldName2'];." &nbsp;&nbsp;&nbsp;&nbsp;";
 echo '</td>
        <td align=left>';
  echo  "&nbsp;&nbsp;&nbsp;&nbsp; ".$r_count['fieldName3'];;
 echo '</td>
 </tr>';
 }
}     
?>
    <tr style="background-color:#000000;">
        <td height="1" colspan="3"></td>                   
    </tr>
 </table>

HTML code that written above php code defines the head of grid.
And the part that involves php code retrieves data from database and it shows the data in grid form

Let me know if i made mistakes.
Good luck

No comments:

Post a Comment