Home
/
PHP & MySQL Tutorials
/
How to Select Individual Records From MySQL Table Tutorial

How to Select Individual Records From MySQL Table Tutorial

As well as showing the whole database table, PHP can be used to select individual records or records which match certain criteria. To do this you should use a variation of the SELECT query. To display the whole table, use:

SELECT * FROM tablename

If you just want to select records which have value=1 in the field1-name row, use the following query:

SELECT * FROM tablename WHERE field1-name='1'

In the same way, you could select records based on any field in the database. You can also search in more fields by adding more:

field='value'

sections into the query.

For example, the following query will select all records which have value=1 in the field1-name row and value=2 in the field2-name row:

SELECT * FROM tablename WHERE field1-name='1' AND field2-name='2'

For further reference, visit the official websites of PHP and MySQL.

Share This Article