Note that there are some explanatory texts on larger screens.

plurals
  1. POcode igniter - sending search term and getting mysql results as json from php using jquery
    text
    copied!<p>i'm new to CI, working on a small search engine, i'll send data from client side using <code>Jquery</code> <code>$.post</code></p> <pre><code>&lt;script&gt; var term=$('#search_term').val(); $.post(search_url,{term:term},function(data){ $("#ajax_response").append( JSON.stringify(data)); }); &lt;/script&gt; </code></pre> <p>and this is how i'm generating Json in CI controller</p> <pre><code>&lt;?php function s() { $term = $_POST['term']; $result = $this -&gt; search_model -&gt; search($term); $cities=array(); foreach ($result as $key =&gt; $bd) { if (!isset($cities[$bd['c_name']])) { $cities[$bd['c_name']]=array(); } $cities[$bd['c_name']][]=$bd; } echo json_encode($cities); } ?&gt; </code></pre> <p>and the json output i'm getting is</p> <pre><code>{"Siddapura":[ { "b_id":"12", "c_id":"2", "b_name":"Sandige Mensu", "b_contactperson":"aaasdf", "b_area":"Siddapura Town", "c_name":"Siddapura" }, { "b_id":"14", "c_id":"2", "b_name":"Hhhh", "b_contactperson":"asdfasfd", "b_area":"Siddapura Town", "c_name":"Siddapura" }], "Other":[ { "b_id":"5", "c_id":"4", "b_name":"Prathvi Home Products", "b_contactperson":"Ganaraj Hegde", "b_area":"Other", "c_name":"Other" }, { "b_id":"6", "c_id":"4", "b_name":"Innond Home Product", "b_contactperson":"Ganaraj Hegde", "b_area":"Other", "c_name":"Other" } ]} </code></pre> <p>Json object names are different every time according to search. i want two outputs from this data. 1)<img src="https://i.stack.imgur.com/Mi45v.png" alt="The result"></p> <p>this is the result i wand to show 2) how many results in which areas... <img src="https://i.stack.imgur.com/teJLi.png" alt="Filtering results"></p> <p>need help in processing <code>json</code> data in <code>Jquery</code> and appending them to <code>div</code> <code>id</code> <code>#ajax_response</code>. thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload