Using Conditionals

The problem with the SELECT statement as I have used it thus far is that it will automatically retrieve every record. While this isn’t a big issue when dealing with a few rows of information, it will greatly hinder the performance of your database as the number of records grows. To improve the efficiency of your SELECT statements, you can use different conditionals in an almost limitless number of combinations. These conditionals use the SQL term WHERE and are written much as you’d write a conditional in PHP.

SELECT * FROM tablename WHERE columnname
→ = 'value'

SELECT email FROM users WHERE last_name
→ = 'Lennon'

SELECT name FROM people WHERE birth_date
→ = '2005-01-26'

Table 4.7 lists the most common operators you would ...

Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.