shadowline
INSERT << SELECT >> WHERE
Query, as in, to ask a question. Working with a database, this concept will be put to very good use.

On the INSERT tutorial page, you've already seen a QUERY in action. The query asked the database to insert the new information into the specified database table.

The SELECT property can be used in a mysql_query command to choose specific information in the database table.

$sql = mysql_query("SELECT * FROM table_name");

The variable $sql is being used to find the information in the address_book table. The * is a symbol meaning "all". It will look at all of the records FROM the specified table.

To look at each row in the specified area, the next step is to use a loop and the mysql_fetch_row command with the SELECT information.

while ($row = mysql_fetch_row($sql)) {
echo "$row[0] $row[1] $row[2] <br />";
}

WHILE the statement is TRUE, the loop will continue.

The mysql_fetch_row command will take the supplied information and read the data from the next available row of the database.

The ECHO command being used to display the data during each row loop is a simple one for example purposes. The columns of a database are numbered starting at zero. The variable $row is assigned the current row contents during each loop.

david_test
address_book
first_name
VARCHAR(25)
0
last_name
VARCHAR(25)
1
phone_number
VARCHAR(15)
2
row1 datarow1 datarow1 data
row2 datarow2 datarow2 data
row3 datarow3 datarow3 data
row4 datarow4 datarow4 data
INSERT << SELECT >> WHERE
shadow

Advertise in the banner along the top, Click here!

Valid XHTML 1.0 Transitional Valid CSS! Text Link Ads
shadow
shadow