php - JSON Return List from Array -
I am trying to create a list of names with the checkbox using AJAX. Unfortunately, using the code given below, I get only one name instead of the four in my database.
The code I am using here sits in a separate php file called by AJAX:
$ query = "SELECT id, first_name, last_name, From e-mail users where location_id = '{$ location_id}' "; $ Result = mysqli_query ($ connection, $ query); If (! $ Result) {dead ("database queries failed:". Mysqli_error ($ connection)); } While ($ line = mysqli_fetch_array ($ result)) {$ name = $ row ['first_name'] "" $ line ['last_name']; $ Attendees = '& lt; Label & gt; & Lt; Input type = "checkbox" name = "emp_name []" id = "emp_name []" value = "'. $ Name.' & Gt; '$ name' & lt; / labels & gt; & lt; span style = "Padding-right: 20px;" & gt; & lt; / span & gt; ';} echo json_encode (array (' present '= & gt; $ present));
Before I try to call this AJAX, my main document had the same query with echo
instead of $ attendees
and it worked flawlessly without any timing It returned to all the four names with the checkbox located around it. A snippet from that code is:
while ($ row = mysqli_fetch_array ($ result)) {$ name = $ row ['first_name'] "" $ line ['last_name']; echo '& Lt; label & gt; & lt; input type = "checkbox" name = "emp_name []" id = "emp_name []" value = "' $ Name '' & Gt; '$ name' & lt; / labels & gt; & lt; span style = "padding-right: 20px;" & gt; & lt; / span & gt; ';}
< / Pre>I am very new to AJAX and therefore I'm not sure where the problem is! Please help!
Comments
Post a Comment