PHP SQL Result
This example illustrates how to display result on the browser and how to use the result in the php application.
To understand how to display the result returned
from the sql query execution, we have created sql_result.php page. First,
connection from database is created using mysql_connect("hostName",
"userName", "Password"), database is selected by
mysql_select_db("databaseName", connectionObject). Now, query "SELECT * FROM users
"
is executed using mysql_query() method to select the data from the table
"users" in the database. The result is stored in the "
result" variable in php. The iteration can be performed using while
statement as given below:
while($row =
mysql_fetch_array($result)){ echo $row['username'] . " " . $row['email']; echo "<br>"; } |
Table: users
Source Code of sql_result.php
<?php |
Output: