PHP MySQL บรรทัด Where

যদি একটি নির্দিষ্ট শর্তের সাথে ম্যাচ করা হওয়া তথ্য পাবেন, তবে SELECT স্ট্যাটমেন্টে WHERE সাবক্লাজ যোগ করুন。

WHERE সাবক্লাজ

যদি একটি নির্দিষ্ট শর্তের সাথে ম্যাচ করা হওয়া তথ্য পাবেন, তবে SELECT স্ট্যাটমেন্টে WHERE সাবক্লাজ যোগ করুন。

গঠনশৈলী

SELECT column FROM table
WHERE column operator value

এই অপারেটরগুলি WHERE সাবক্লাজের সাথে ব্যবহার করা যায়:

Operators Description
= Equal
!= Not equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
BETWEEN Between a range of values
LIKE Search for a matching pattern

Note:SQL statements are case-insensitive. WHERE is equivalent to where.

To make PHP execute the above statement, we must use the mysql_query() function. This function is used to send queries and commands to the SQL connection.

Example

The following example will select all rows from the 'Persons' table where FirstName='Peter':

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");
while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }
?>

The output of the above code:

Peter Griffin