php - Autocomplete box will not populate from the database -


so tried setting autocomplete box through codeignighter framework , cannot seem textbox populate results database.

this model

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  class nextcreatecampaign_model extends ci_model {  public function __construct() {      parent::__construct();      // own constructor code            }  function getuser($term) {  $sql = $this->db->query('select campaign_name, remote_service_id ad_report_new.service remote_service_id "'. mysql_real_escape_string($term) .'%" order remote_service_id');  return $sql ->result(); } } ?> 

this controller campaign.php

    <?php if ( ! defined('basepath')) exit('no direct script access allowed');  class campaign extends ci_controller {  /**  * index page controller.  *  * maps following url  *      http://example.com/index.php/campaign  *  - or -    *      http://example.com/index.php/campaign/index  *  - or -  * since controller set default controller in   * config/routes.php, it's displayed @ http://example.com/  *  * other public methods not prefixed underscore  * map /index.php/campaign/<method_name>  * @see http://codeigniter.com/user_guide/general/urls.html  */   function __construct() { parent::__construct(); $this->load->model('nextcreatecampaign_model'); } public function index(){ $this->load->helper('url'); $this->load->view('nextcreatecampaign'); }  public function getuseremail() {   if ( !isset($_get['term']) ) exit; $term = $_request['term'];     $data = array();     $rows = $this->nextcreatecampaign_model->getuser($term);         foreach( $rows $row )         {             $data[] = array(                 'label' => $row->remote_service_id.', '. $row->email,                 'value' => $row->remote_service_id);   // here taking name value     display name in text field, can change per choice.         }      echo json_encode($data);      flush();  }   }  /* end of file campaign.php */ /* location: ./application/controllers/campaign.php */ 

and view

!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>create/edit pay performance campaigns</title> <link rel="stylesheet" type="text/css" href="/assets/css/style.css" />     <script src="http://code.jquery.com/jquery-1.8.3.js"></script> <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>     <script type="text/javascript">    $(document).ready(function(){   function split( val ) {             return val.split( /,\s*/ );     }             function extractlast( term ) {              return split( term ).pop();     }      $( "#txtinput" )         // don't navigate away field on tab when selecting item           .bind( "keydown", function( event ) {             if ( event.keycode === $.ui.keycode.tab &&                     $( ).data( "autocomplete" ).menu.active ) {                 event.preventdefault();             }         })         .autocomplete({             source: function( request, response ) {                 $.getjson( "<?php echo base_url();?>index.php/campaign/getuseremail",{                     term: extractlast( request.term )                 },response );             },             search: function() {                 // custom minlength                 var term = extractlast( this.value );                 if ( term.length < 1 ) {                     return false;                 }             },             focus: function() {                 // prevent value inserted on focus                 return false;             },             select: function( event, ui ) {                 var terms = split( this.value );                 // remove current input                 terms.pop();                 // add selected item                 terms.push( ui.item.value );                 // add placeholder comma-and-space @ end                 terms.push( "" );                 this.value = terms.join( "," );                 return false;             }         });   });  </script>   </head>  <style> #txtinput{width:400px;height: 30px;border-radius:8px;border:1px solid #999;}  </style>  <body> <input type="text" id="txtinput" size="20" /> </body> 


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -