Web Design

(Nancy Kaufman) #1

310


Search the Database (continued)


( Type else.
) Type {.
q Type while($row =
mysql_fetch_array
($data, MYSQL_
ASSOC)).
w Type {.
e Type echo statements to
output the results.
r Type }.
t Type }.
y Type ?>.
u Save the page in the server’s
Web root.

# Type $data =
mysql_query
($query);.

$ Type $num_records =
mysql_num_
rows($data);.

% Type if($num_records
== 0).
^ Type {.

& Type echo “No records
found”;.
* Type }.

Search the Database (continued)


O


nce you have queried the database, you can simply display the results as you would normally,
by converting the results into an array and using the where loop to iterate over them. You can
also use the mysql_num_rows() function to display the number of rows the query returns, which
can be helpful to your user. If your query returns no results, you can use a PHP if statement, which
takes an expression that returns true or false, to display a message. You can add an else statement

to display the results when the query is successful.


14


15


18 17


13


16


(^2021)


23


19


22


24


25


26

Free download pdf