0

This is controller

public function index()
{

    $this->load->view('view_demo');
}
public function search($id)
{
    $id         = $this->input->get('id');
    $data['id'] = $this->datacomplete->information($id);
    $this->load->view('view_demo', $id);
}

This is model

public function information($id)
{
    $q = $this->db->select('*')->from('autocomplete')->where('id', $id)->get();
    return $q->result();
}

This is view

<body style="background-color: #000000;">
    <?php echo $id; ?>
    <form action="<?php echo base_url('autocomplete/search/' .$id); ?>" method="get">
        <div class="row">
            <center>
                <h2 style="color: #fff;">AUTOCOMPLETE FORM FROM DATABASE USING CODEIGNITER AND AJAX</h2>
            </center>
            <div class="col-md-4 col-md-offset-4" style="margin-top: 200px;">
                <label class="control-lable" style="color: #fff;">Country Name</label>
                <input style="height:70px" type="text" id="country" autocomplete="off" name="country" class="form-control" placeholder="Type to get an Ajax call of Countries">
                <ul class="dropdown-menu txtcountry" style="margin-left:15px;margin-right:0px;" role="menu" aria-labelledby="dropdownMenu" id="DropdownCountry"></ul>
                <button location.href='<?php echo site_url().'/autocomplete/search?id='.$id;?>' type="submit">Submit</button>
            </div>
        </div>
    </form>
</body>

I have an index function and view_demo page where a search bar is present when I search form country name ie India in the search bar and then submit the search bar it redirects me to search.php and in url I will get the country id.

For example: http://localhost/codeajax/Autocomplete/search?id=233 : Here 233 is the country id of India.

I have to do this dynamically in URL of the search page.

Here the search page is now while blank page and one more I also want to echo the country id on the search page. ie 233 on the blank page.

Rahul
  • 18,271
  • 7
  • 41
  • 60

1 Answers1

0

Controller

public function index()
{

    $this->load->view('view_demo');
}
public function search($id)
{
    $id         = $this->input->get('id');
    $data['id'] = $this->datacomplete->information($id);
    $this->load->view('view_demo', $data);
}

Model

public function information($id)
{
    $q = $this->db->select('*')->from('autocomplete')->where('id', $id)->get();
    return $q->result();
}

View

<body style="background-color: #000000;">
    <?php echo $id; ?>
    <form action="<?php echo base_url('autocomplete/search/' .$id); ?>" method="get">
        <div class="row">
            <center>
                <h2 style="color: #fff;">AUTOCOMPLETE FORM FROM DATABASE USING CODEIGNITER AND AJAX</h2>
            </center>
            <div class="col-md-4 col-md-offset-4" style="margin-top: 200px;">
                <label class="control-lable" style="color: #fff;">Country Name</label>
                <input style="height:70px" type="text" id="country" autocomplete="off" name="country" class="form-control" placeholder="Type to get an Ajax call of Countries">
                <ul class="dropdown-menu txtcountry" style="margin-left:15px;margin-right:0px;" role="menu" aria-labelledby="dropdownMenu" id="DropdownCountry"></ul>
                <button location.href='<?php echo site_url().'/autocomplete/search?id='.$id;?>' type="submit">Submit</button>
            </div>
        </div>
    </form>
</body>
Maruthi Prasad
  • 170
  • 1
  • 12
  • Read the Question properly –  Apr 08 '19 at 12:26
  • At first, it will give you $id undefined. – M.Hemant Apr 08 '19 at 12:27
  • @M.Hemant Now i have elaborate the question properly .....u just read the question –  Apr 08 '19 at 12:30
  • @M.Hemant i have two view page one is view_demo where search bar is there and on submit redirect to search.php page with following url http://localhost/codeajax/Autocomplete/search?id=233 in search page –  Apr 08 '19 at 12:33
  • First thing, are you getting any $id undefined error? At first when it comes from index page – M.Hemant Apr 08 '19 at 12:38
  • @M.Hemant yes i m getting undefined id in model code ... $q = $this->db->select('*')->from('autocomplete')->where('id', $id)->get(); –  Apr 08 '19 at 12:59
  • @M.Hemant i m getting this in url http://localhost/codeajax/%3Cdiv%20style=?country=Russian+Federation –  Apr 08 '19 at 13:04
  • have a look here :https://stackoverflow.com/questions/2894250/how-to-make-codeigniter-accept-query-string-urls – PHP Geek Apr 09 '19 at 12:40