Prev | Current Page 89 | Next

Larry Ullman

"Building a Web Site with Ajax: Visual QuickProject Guide"

(See
extra bits on page 125.)
4 The mysql_real_escape_
string() function makes it
safe to use the submitted value
in a query.
??¦

???;
if (!empty($_GET[???last_name??™])) {
require_once(???mysql.inc.php??™);
$q = ???SELECT CONCAT(last_name, ???, ???, first_name),
email, department FROM employees LEFT JOIN departments
USING (department_id) WHERE last_name LIKE ?????? .
mysql_real_escape_string($_GET[???last_name??™]) . ???%??™
ORDER BY last_name, first_name???;
$r = mysql_query($q, $dbc);
108 enabling an Ajax search
fetch the results
1 Check that at least one
record was returned.
2 Fetch all the records and
print them out as XML data.
3 The newline character (\n) makes sure that whatever is
printed next will go on the following line (like hitting Enter or
Return on your keyboard).
??¦
$r = mysql_query($q, $dbc);
if (mysql_num_rows($r) > 0) {
while ($row = mysql_fetch_array($r, MYSQL_NUM)) {
echo ???
$row[0]
$row[2]
$row[1]
\n???;
} // End of WHILE loop.
} // End of IF.
enabling an Ajax search 109
complete the PHP
1 Close the database connection
(not required, but good form).


Pages:
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101