PHP MySql WHERE clause

PHP MySql WHERE clause tutorial will explain you How to use MySQL WHERE clause in PHP? with example. When we want select only data that matches a specified criteria, at that time MySQL WHERE clause is used with MySQL Select, same as filters.

PHP MySQL WHERE clause

If we want to select only certain entries of our table, then we can use the keyword WHERE.

Syntax for PHP MySql WHERE clause:

condition(s)” – is one or more conditionals that specifies the select criteria.
These conditions can use comparison, arithmetic and logical operators.

The table below lists the most common operators in MySQL WHERE expressions:

Operator Meaning Example
= Equals WHERE ‘id’=3
< Less than WHERE ‘id'<3
> Greater than WHERE ‘id’>3
<= Less than or equal to WHERE ‘id'<=3
>= Greater than or equal to WHERE ‘id’>=3
!= (also <>) Not equal to WHERE ‘id’!=3
IS NOT NULL Has a value WHERE ‘id’ IS NOT NULL
IS NULL Does not have a value WHERE ’email’ IS NULL
BETWEEN min AND max Within a specific range (min and max) WHERE ‘id’ BETWEEN 2 and 4
NOT BETWEEN min AND max Not within a specific range (min and max) WHERE ‘id’ NOT BETWEEN 2 and 4
IN(val1, val2, val3) Found within a list of values WHERE ‘id’ IN(1, 3, 4)
OR Where one of two conditions is true WHERE ‘id’>3 OR ‘name’=’MarPlo’
AND Where both conditions are true WHERE ‘id’>3 AND ‘name’=’MarPlo’

Example on PHP MySql WHERE clause:

Here we will display the information of users whose first name is “Jon”.
We use a table containing the following fields:

  • ID – auto generated integer
  • FName – First Name, varchar
  • LName – Last Name, varchar
  • PHONE – Phone number, varchar

Output:

1 Jon Job
SHARE
Previous articlePHP MySql Select Query
Next articlePHP MySql ORDER BY
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!