Not quite sure what you're trying to achieve, but I assume you want to
take some form data, form a query string, and submit to a server side
script (php) that will handle the db query. I would use an html form
with a submit button. Something like:

<form action="dbscript.php" method="POST">
<input type="text" name="queryString"/>
<input type="submit" value="Get Results"/>
</form>

No AJAX here -- one the query string is filled out in the form and the
submit button is clicked, it will send a post to the server hosting
dbscript.php, and your php code will take it from there. If you don't
want to redraw the page, you could make a function in jquery to load
the servers response into a portion of the page, and call that
function via the forms onsubmit attribute.

So, perhaps something like:

<form action="#" method="POST" onsubmit="return loadStuff()">
<input type="text" name="queryString"/>
<input type="submit" value="Get Results"/>
</form>

<script type="text/javascript">
function loadStuff(){
       $.post("dbquery.php",
                 {queryString:"foobar"},
                 function(returned_data)
                              {
                                $('#output').html(returned_data);
                              });
       return false;
}
</script>

Don't forget the return false :)

This is all completely untested -- just a suggestion on a possible way
to handle the problem.



On Aug 28, 3:36 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi,
> I am having my first foray into the world of AJAX and Javascript and
> have created an Autosuggest search page. However, I want to have a
> submit button that will list all database entreies that match the
> search query and I can't work out what the best way to do this! Would
> it be using a input button and some kind of onClick fucntion? If so,
> does anyone know what the onClick function would be in jQuery? Would I
> need to create some new script for this? If anyone can give me any
> guidance on this I will be eternally grateful. Here is the code:
>
> <?php
> $db = new mysqli('128.0.0.1', 'asad' ,'asad', 'asad');
>         if(!$db) {
>                 echo 'ERROR: Could not connect to the database.';
>         } else {
>                 if(isset($_POST['queryString'])) {
>                         $queryString = 
> $db->real_escape_string($_POST['queryString']);
>
>                         if(strlen($queryString) >0) {
>
>                                 $query = $db->query("SELECT DISTINCT OrgType 
> FROM Contacts WHERE
> OrgType LIKE '$queryString%' LIMIT 10");
>                                 if($query) {
>
>                                         while ($result = $query 
> ->fetch_object()) {
>
>                                         echo '<li 
> onClick="fill(\''.$result->OrgType.'\');">'.
> $result->OrgType.'</li>';
>                                 }
>                                 } else {
>                                         echo 'ERROR: There was a problem with 
> the query.';
>                                 }
>                         } else {
>                         }
>                 } else {
>                         echo 'There should be no direct access to this 
> script!';
>                 }
>         }
> ?>

Reply via email to