MySQLi Where Clause using php
The WHERE clause is used to extract only those records that fulfill a specified condition. where clause is a part of select command . it is used to fetch data from a table . we basically use this clause to filter out our results. by using where clause we can select particular set of records based specified condition.
SELECT column_name1,column_name2 FROM table_name WHERE column_name = value
<?php
$host = "localhost";
$user = "";
$pass = "";
$dbname = "users";
$conn = mysqli_connect($host,$user,$pass,$dbname) or die(mysqli_error($conn));
$userId=2;
$sql = "SELECT * FROM users where id=".$userId;
$retval=mysqli_query($conn,$sql);
if(mysqli_num_rows($retval) > 0){
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Salary</th></tr>";
while($row= mysqli_fetch_array($val))
{
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['salary']."</td>";
echo "</tr>";
}
echo "</table>";
}else{
echo "0 results";
}
mysqli_close($conn);
?>
id | name | salary |
---|---|---|
2 | Name2 | 70000 |
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning