0

I am trying to intergrate the jquery tokenInput plugin to my form Link I want to simple local data search I want data to be fetched from database and show it in input box with multiple options as in demo However this code works for me it displays the result[i use codeigniter]

//working but want to fetch from database
<script type="text/javascript">
$(document).ready(function() {
    $("#demo-input-local").tokenInput([
        {id: 7, name: "Ruby"},
        {id: 11, name: "Python"},
        {id: 13, name: "JavaScript"},
        {id: 17, name: "ActionScript"},
        {id: 19, name: "Scheme"},
        {id: 23, name: "Lisp"},
        {id: 29, name: "C#"},
        {id: 31, name: "Fortran"},
        {id: 37, name: "Visual Basic"},
        {id: 41, name: "C"},
        {id: 43, name: "C++"},
        {id: 47, name: "Java"}
    ]);
});
</script>

but when I try to fetch data from database it's does not working

here what I have tried in url i have given the url of my controller where my model will be loaded which is responsible for fetching the data.First problem I am facing is how to add HTTP get parameter to my sql and second in getting proper json format which is required to show the result as stated in documentation. Here is code

//My Controller
function get_countries() 
{
    $this->load->model("register_modal");
    $result=$this->register_modal->getCountries();
    var_dump($result);
}

//Model for fetching data
function getCountries()
{
    $sql = 'SELECT  `country_name` FROM nm_country,`$_GET["q"]`';
    $query = $this->db->query($sql);
    $result = $query->result_array();
    return $result;
    foreach ($result as $row) {
        $json_response = json_encode($row);
    }

    # Optionally: Wrap the response in a callback function for JSONP cross-domain support
    if ($_GET["callback"]) {
        $json_response = $_GET["callback"] . "(" . $json_response . ")";
    }

    echo $json_response;        
}

javascript in form

<script type="text/javascript">
            $(document).ready(function() {
                $("#wish_city").tokenInput('<?php echo base_url('Register/get_countries?queryParam=q')?>',
                        queryParam: 'q',
                        tokenLimit: 1,
            });
    </script>
2
Contributors
4
Replies
31
Views
2 Years
Discussion Span
Last Post by anmol.raghuvanshi1
1

I just started using the same library for a project too.
You haven't mentioned what the parameter matches in the database so I'll assume you want to check for a country name that equals the q parameter (not the correct case I know).
In this case you can do this:
$sql = 'SELECT country_name FROM nm_country where country = '" . $_GET["q"] . "';

0

actually i am getting undefined q
SELECT country_name FROM nm_country WHERE country_name =
what i am doing wrong is this not correct way to pass parameter

$(document).ready(function() {
            $("#wish_city").tokenInput("<?php echo base_url('Register/get_countries?queryParam=q')?>", {
                queryParam: 'q',
                resultLimit:10,
        }); });

Edited by anmol.raghuvanshi1

1

Alter your URL to be just the path with no parameters
<?php echo base_url('Register/get_countries')?>
As you have it, the post parameters don't include a parameter called 'q', only $_POST['queryParam'] should exist.
So, you can either edit the script to read the correct $_POST variable or take out the query from your URL and remove the default parameter name (the queryParam: q part)

0

Could you give some more information i didn't understand above explanation

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.