Home >>MySQL Tutorial >PHP MySQL Select
To display all data from a table use select(*) statement and to display particular field's data use select filed1,filed2 at the place of (*).
SyntaxSELECT column1, column2, column3,... FROM table_name //OR SELECT * FROM table_name
<?php //connect database $con=mysqli_connect("localhost","root","","Employee") or die(mysqli_error()); //select all values from empInfo table $data="SELECT * FROM empInfo"; $val=mysqli_query($con,$data); while($r=mysqli_fetch_array($val)) { echo $r['emp_id']." ".$r['name']." ".$r['email']." ".$r['mobile']."<br/>"; } ?>
<?php //connect database $con=mysqli_connect("localhost","root","","Employee") or die(mysqli_error()); //select all values from empInfo table $data="SELECT * FROM empInfo"; $val=mysqli_query($con,$data); while(list($id,$name,$eid,$mob) = mysqli_fetch_array($val)) { echo $id." ".$name." ".$eid." ".$mob."<br/>"; } ?>
<?php //connect database $con=mysqli_connect("localhost","root","","Employee") or die(mysqli_error()); //select values from empInfo table $data="SELECT * FROM empInfo"; $val=mysqli_query($con,$data); echo "<table border='1'>"; echo "<tr><th>Emp_id</th><th>Name</th><th>Email</th><th>Mobile</th></tr>"; while(list($id,$name,$eid,$mob)= mysql_fetch_array($val)) { echo "<tr>"; echo "<td>".$id."</td>"; echo "<td>".$name."</td>"; echo "<td>".$eid."</td>"; echo "<td>".$mob."</td>"; echo "</tr>"; } echo "</table>"; ?>