27.10.2015 Views

AJAX and PHP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>AJAX</strong> Suggest <strong>and</strong> Autocomplete<br />

170<br />

'FROM suggest ' .<br />

'WHERE name=""';<br />

// execute the SQL query<br />

$result = $this->mMysqli->query($query);<br />

// build the XML response<br />

$output = '';<br />

$output .= '';<br />

// if we have results, loop through them <strong>and</strong> add them to the output<br />

if($result->num_rows)<br />

while ($row = $result->fetch_array(MYSQLI_ASSOC))<br />

$output .= '' . $row['name'] . '';<br />

// close the result stream<br />

$result->close();<br />

// add the final closing tag<br />

$output .= '';<br />

// return the results<br />

return $output;<br />

}<br />

//end class Suggest<br />

}<br />

?><br />

8. Create a new file named index.html, <strong>and</strong> add this code to it:<br />

<br />

<br />

<br />

<strong>AJAX</strong> Suggest <strong>and</strong> Autocomplete<br />

<br />

<br />

<br />

<br />

<br />

<br />

Your browser does not support JavaScript!!<br />

<br />

<br />

Enter the first letters of your function:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

9. Create another file named suggest.css, <strong>and</strong> add this code to it:<br />

body<br />

{<br />

font-family: helvetica, sans-serif;<br />

margin: 0px;<br />

padding: 0px;<br />

font-size: 12px<br />

}<br />

#content<br />

{<br />

height: 100%;<br />

width: 100%;<br />

text-align:center<br />

}<br />

#message<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!