If you have already register Login here.
MySQL 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 = mysql_connect($host,$user,$pass) or die(mysql_error());
if(!$conn){
die("Could not connect:".mysql_connect_error());
}
// select database
mysql_select_db($dbname,$conn);
$userId=2;
$sql = "SELECT * FROM users where id=".$userId;
$retval=mysql_query($sql);
if(mysql_num_rows($retval) > 0){
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Salary</th></tr>";
while($row= mysql_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";
}
mysql_close();
?>
id | name | salary |
---|---|---|
2 | Name2 | 70000 |
© 2025 Easy To Learning. All Rights Reserved | Design by Easy To Learning