anantamu.com


PHP MySQL WHERE Keyword


The WHERE Keyword is used to get perticular data from table


WHERE Keyword

SELECT columnNames FROM tableName WHERE columnNames=value;

Show the perticular data from table

Displaying the records from Profile table.

<?php
$servername = "localhost";
$username1 = "root";
$password1 = "";
$dbname = "sample";
//server connection
$connection = mysqli_connect($servername, $username1, $password1, $dbname);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
$sqlQuery='select * from profile WHERE id="1" ';


$resultSql=mysqli_query($connection, $sqlQuery);
echo '<table>';
echo '<tr><td>Name</td><td>Address</td></tr>';

if (@mysqli_num_rows(@$resultSql) >= 1) {
// output data of each row
  while ($rowValue = mysqli_fetch_assoc($resultSql)) {
	  echo '<tr>';
	  echo '<td>'.$rowValue['Name'].'</td>';
	  echo  '<td>'.$rowValue['Address'].'</td>';
	  echo '</tr>';

  }
}else{	
	echo '<tr><td>no records found</td><td></td></tr>';
}
echo '</table>';
mysqli_close($connection);
?>