Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hope this will help you.</p> <p><strong>Controller: [I am writing only the functions.]</strong></p> <pre><code>public function customer_details() { $data['base_url'] = base_url(); $data['somedata'] = 'somevalue'; $this-&gt;load-&gt;view('customerDetailsView',$data); } public function ajax_fetchDetails() { $customerName = $this-&gt;input-&gt;post('cname'); $this-&gt;load-&gt;model('customerDetails'); $cdetails = $this-&gt;customerDetails-&gt;fetchdetails($customerName); if(!empty($cdetails)) { echo json_encode($cdetails); } else echo '0'; //Handle it in view. } </code></pre> <p><hr/> <strong>Model: [Write your own Query]</strong></p> <pre><code>Select * from `customerdetails` where `name` like $customerName limit = 1; </code></pre> <p><hr/> <strong>View: customerDetailsView [I am writing only what should appear in the tag]</strong></p> <pre><code>&lt;label for='cname'&gt;Customer Name:&lt;/label&gt; &lt;input type="text" id="cname" /&gt; &lt;br/&gt; &lt;input type="button" id="fetchbtn" value="Fetch Details" /&gt; &lt;br/&gt; &lt;label for='email'&gt;Email: &lt;/label&gt; &lt;input type="text" id="email" /&gt; &lt;label for='fax'&gt;Fax: &lt;/label&gt; &lt;input type="text" id="fax" /&gt; </code></pre> <p>... So on Untill all the details are covered.</p> <pre><code>&lt;!--For the following script to work you'll have to use jquery library.--&gt; &lt;script type="text/javascript"&gt; $("#fetchbtn").onclick( function(event) { var name = jQuery.trim($("#cname").val()); //Fetch the customer name enter in the input field. if(name != '') // Check for empty condition { $.ajax({ type: "POST", url:"&lt;?php echo $base_url.'&lt;CONTROLLER NAME&gt;/ajax_fetchDetails'; ?&gt;", data:{cname:name}, success: function(result) { if(result != '0') { var customerDetails = JSON &amp;&amp; JSON.parse(result) || $.parseJSON(result); // Parse the JSON encoded customer details into string. var email = customerDetails.email, fax = customerDetails.fax; //... So on $("#email").val(email); $("#fax").val(fax); //... So on } } }); } }); &lt;/script&gt; </code></pre> <p>The only disadvantage here is, if two customers have same name only the 1st customer's details will be fetched. To avoid this, you'll have to maintain unique username for each customer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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