Welcome Guest, Not a member yet? Register   Sign In
Query Questions... newbie
#1

[eluser]Unknown[/eluser]
I am creating my first CI sample app I need some help trying to query through some car inventory

I am trying to create a menu with available makes & models, how do I loop through the available inventory to return all like makes & models from the table. Thanks for any help.

<div>Make 1
<ul>
<li>Model 1 (Count)</li>
<li>Model 2 (Count)</li>
<li>Model 3 (Count)</li>
</ul>
</div>
<div>Make 2
<ul>
<li>Model 1 (Count)</li>
<li>Model 2 (Count)</li>
<li>Model 3 (Count)</li>
</ul>
</div>
#2

[eluser]Davcon[/eluser]
Hi,

I'll assume that you know how to build a model that does database queries. I'll also assume that you know how to build view pages and you know how get them to display variables.

So, here's how I'd do it...

ON YOUR CONTROLLER...
Code:
&lt;?php
session_start();
class Cars extends Controller {
    function Cars() {
        parent::Controller();
    }





function index() {

    //get all the makes from the database...
    $this->load->model('cars_model');
    $makes=$this->car_model->get_makes();

        //now, start building up an html string that contains
        //all of the information about the makes and models...

        if (!isset($html)) {
        $html="";
        }



                   foreach($makes as $make) {
                        $html.="<ul>$make</ul>";
                            $models=$this->car_model->get_models($make);                        
                            foreach($models as $model) {
                            $html.="<li>$model</li>";
                            }
                   }

$data['html']=$html;
$this->load->view('cars', $data);

}
?&gt;

cheap bike insurance

bike insurance
#3

[eluser]Unknown[/eluser]
Thanks this was just what I was looking for.
#4

[eluser]Davcon[/eluser]
No problem mate. Rock on!




Theme © iAndrew 2016 - Forum software by © MyBB