جملة Where في MySQL
- Previous Page MySQL Select
- Next Page MySQL Order By
للتحقق من البيانات التي تتوافق مع الشروط المحددة، يرجى إضافة جملة WHERE إلى جملة SELECT.
جملة WHERE
للتحقق من البيانات التي تتوافق مع الشروط المحددة، يرجى إضافة جملة WHERE إلى جملة SELECT.
النحو
SELECT عمود من جدول WHERE عمود مشغل قيمة
المشغلات التالية يمكن استخدامها مع جملة WHERE:
Operators | Description |
---|---|
= | Equal |
!= | Not equal |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
BETWEEN | Between a range containing |
LIKE | Search for matching patterns |
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 selects 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 is:
Peter Griffin
- Previous Page MySQL Select
- Next Page MySQL Order By