0

My input field should receive autocomplete values from a readbean php datasource

Table that I want to get is "user" and the attribute is "name"

I dont now how to do this at all I tried this but it does not work Error Parse error: parse error in

$( "#enterUser" ).autocomplete({
    source:<?php$users = R::findAll('users');
        foreach ($users as $user) {
            echo '<option value="'. $user->name .'" ';
            if($_POST['filterUser'] == $user->name){
                echo "selected";
            }
            echo '>' . $user->name . '</option>';
        }               
    ?>
});

Can somebody please explain how to attach my user Table to be the source of the autocomplete ?

TNK
  • 1
  • 2

1 Answers1

0

As far as I understand your question, you are mixing client- and server-side code here.

client-side code is everything that runs in your browser, in your case the javascript/query snippet. This part of your application can directly interact with the user (like in your example, react on press of a key)

server-side code is in your case php. it is important to note that server-side code is only executed after a HTTP request.

So in order to get your autocomplete example to work, you need to separate your concerns:

  1. in the client, the autocomplete widget must be configured to trigger an HTTP request (which runs in the background and is called AJAX request for such cases). The relevant documentation for this can be found at http://api.jqueryui.com/autocomplete/#option-source.

For a sample, have a look at this answer

  1. on the server, you have to provide an endpoint for the query string which triggers the database lookup and responds with the autocomplete suggestions. For information about the required return format, have a look at this answer
Community
  • 1
  • 1
Peter Sorowka
  • 1,036
  • 9
  • 20