Previous page we were discussed 2 ways of displaying mysql data.Here, I am going to show you the other methods of displaying data. I used my_database table biodata. following files show you the other ways of displaying mysql data.
Example:-01
<table border=1><tr><td>First Name</td><td>Last Name</td><td>Age</td></tr> <?php $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbName = 'my_database'; $dbConn = mysql_connect ($dbHost,$dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); $query = "SELECT * FROM biodata"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while($i<$num){ $FirstName=mysql_result($result,$i,1); $LastName=mysql_result($result,$i,2); $Age=mysql_result($result,$i,3); ?> <tr><td><?php echo $FirstName;?></td><td><?php echo $LastName;?></td><td><?php echo $Age;?></td></tr> <?php ++$i; } ?> </table> |
Example:-02
<table border=1><tr><td>First Name</td><td>Last Name</td><td>Age</td></tr> <?php $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbName = 'my_database'; $dbConn = mysql_connect ($dbHost,$dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); $Query="SELECT * from biodata"; $dbresult=mysql_query($Query); if(mysql_num_rows($dbresult) >0) { while($row=mysql_fetch_row($dbresult)) { ?> <tr><td><?php echo $row[1];?></td><td><?php echo $row[2];?></td><td><?php echo $row[3];?></td></tr> <?php } } ?> </table> |
No comments:
Post a Comment