How to Select a Table from a MysQL Database Using PHP



PHP


In this tutorial, we will show how you can select a table from a MySQL database using PHP, so you can then display that table.

If you have a database comprised of many different tables, PHP has a SELECT function which allows you to select which table you want.

The format to do this is:

Below we give you a table, which is called Fruits (as it represents different types of fruits), which we have selected from a MySQL database:

Fruits

Cantaloupe
$3.99
Honeydew
$4.99
Mango
$1.99
Banana
$0.79

Below is the full code to create the table above:



The line SELECT FROM * $table selects all of the columns from the table assigned to the PHP variable $table. The first half SELECT * deals with the selection of columns of the table and the second half FROM $table chooses the table on the MySQL database which is selected.

This is how MySQL table selection works using PHP.


HTML Comment Box is loading comments...