Select model according to brand

Asked

Viewed 37 times

1

I have the function that returns all registered tags: (With the ID and TAG fields)

public function lista(){

        $lista = array();

        $n = 0;
        $db = new mysql();
        $exec = $db->executar("SELECT * FROM automovel_marca order by marca asc");
        while($data = $exec->fetch_object()){

            $lista[$n]['id'] = $data->id;
            $lista[$n]['marca'] = $data->marca;

            $n++;
        }
        return $lista;
}

And the function that returns the models: (With the fields ID, IDMARK and MODEL)

public function lista(){

        $lista = array();

        $n = 0;
        $db = new mysql();
        $exec = $db->executar("SELECT * FROM automovel_modelo order by modelo asc");
        while($data = $exec->fetch_object()){

            $lista[$n]['id'] = $data->id;
            $lista[$n]['idmarca'] = $data->idmarca;
            $lista[$n]['modelo'] = $data->modelo;

            $n++;
        }
        return $lista;
}

I was able to pull them individually in FORMS, the problem is that I wanted the FORM MODEL field to be related to the BRAND field, when the person selects the brand it displays all the models referring to that brand.

The structure of DB is like this:

car brand (id, brand) automobile model (id,idmark,model) - in this case the idmark follows the relation of the car ID

1 answer

1

I don’t know the structure of your tables, but let’s basically change the two locations below in the methodical model automobile list:

public function lista($idmarca){

        $exec = $db->executar("SELECT * FROM automovel_modelo where idmarca = ".$idmarca." order by modelo asc");

Ai when calling the model car listing you would pass the $idmarca parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.