How to display content of mysql table to php page | AkshayBSoputions
1.Create database with name ProjectDb in mysql.
2. Create table accounts.
3. Write following code to your editor.
<?php
$con=mysqli_connect("localhost","root","","ProjectDb");
?>
<html>
<head>
<style type="text/css">
table{
width:50%;
margin-left:25%;
}
</style>
</head>
<body>
<table border="1">
<tr>
<th>UN</th>
<th>EMAIL</TH>
<th>CONTACT</th>
</tr>
<?php
$query="select * from accounts";
$i=0;
$result=mysqli_query($con,$query);
while($row=mysqli_fetch_assoc($result)){
if($i%2==0){
?>
<tr>
<td><?php echo $row['UN'] ?></td>
<td><?php echo $row['EMAIL'] ?></td>
<td><?php echo $row['CONTACT'] ?></td>
</tr>
<?php
}else{
?>
<tr bgcolor="gray">
<td><?php echo $row['UN'] ?></td>
<td><?php echo $row['EMAIL'] ?></td>
<td><?php echo $row['CONTACT'] ?></td>
</tr>
<?php
}
$i++;
}
?>
</table>
</body>
</html>
4. Save the file in htdocs folder.
5. Check output in browser.
6.Done!!!
To see video for this click on: https://youtu.be/yb3KUliu3_Q
2. Create table accounts.
3. Write following code to your editor.
<?php
$con=mysqli_connect("localhost","root","","ProjectDb");
?>
<html>
<head>
<style type="text/css">
table{
width:50%;
margin-left:25%;
}
</style>
</head>
<body>
<table border="1">
<tr>
<th>UN</th>
<th>EMAIL</TH>
<th>CONTACT</th>
</tr>
<?php
$query="select * from accounts";
$i=0;
$result=mysqli_query($con,$query);
while($row=mysqli_fetch_assoc($result)){
if($i%2==0){
?>
<tr>
<td><?php echo $row['UN'] ?></td>
<td><?php echo $row['EMAIL'] ?></td>
<td><?php echo $row['CONTACT'] ?></td>
</tr>
<?php
}else{
?>
<tr bgcolor="gray">
<td><?php echo $row['UN'] ?></td>
<td><?php echo $row['EMAIL'] ?></td>
<td><?php echo $row['CONTACT'] ?></td>
</tr>
<?php
}
$i++;
}
?>
</table>
</body>
</html>
4. Save the file in htdocs folder.
5. Check output in browser.
6.Done!!!
To see video for this click on: https://youtu.be/yb3KUliu3_Q
Comments
Post a Comment