Welcome Guest, Not a member yet? Register   Sign In
controller load to typeahead
#1

Hi coders,

any body can review, if what is wrong with following . . it cannot work.


views
Code:
<script>
        $(document).ready(function()
            {
            
                $('input.stocks_list').typeahead({
                  name: 'stocks_list',
                  prefetch : '<?php echo base_url();?>home/stocks_list'
                });

            })
    </script>
Code:
<input type="text" name="stocks_list" size="20" class="stocks_list" placeholder="Required *">


Controller
Code:
public function stocks_list()
   {
         $query = $_REQUEST['query'];
         $sql = $this->db->query("SELECT * FROM stocks");
         foreach($sql->result_array() as $row)
             {
            echo $row['description'];
             }
                echo json_encode ($array);     
    }
Reply
#2

(02-24-2015, 08:58 PM)jaysondotp Wrote: Hi coders,

any body can review, if what is wrong with following . . it cannot work.


views

Code:
<script>
$(document).ready(function()
{

$('input.stocks_list').typeahead({
 name: 'stocks_list',
 prefetch : '<?php echo base_url();?>home/stocks_list'
});

})
</script>
Code:
<input type="text" name="stocks_list" size="20" class="stocks_list" placeholder="Required *">


Controller

Code:
public function stocks_list()
  {
        $query = $_REQUEST['query'];
        $sql = $this->db->query("SELECT * FROM stocks");
        foreach($sql->result_array() as $row)
            {
       echo $row['description'];
            }
               echo json_encode ($array);
   }


Maybe:

PHP Code:
public function stocks_list()
{
 
        $query $_REQUEST['query'];
 
        $sql $this->db->query("SELECT * FROM stocks");

         
$array = array();

 
        foreach($sql->result_array() as $row)
 
        {
 
               $array[] = $row['description'];
 
        }
 
        echo json_encode ($array); 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB