0

と の 2 つのテーブルがmarkersありmarkers_typesます。

markers
id, type_id,    lat,    lng
1   1           42.000  2.500
2   1           41.000  2.400
3   2           40.000  2.300

markers_types
id, name,   image
1   TYPE1   type1.png
2   TYPE2   type2.png

DB から行を正しく取得するにはどうすればよいですか。たとえば、最初の行のmarkers列が にtype_id設定されている場合、が等しい1他のテーブルの対応する ID から画像を出力したいですか? ばかげた質問で申し訳ありませんが、それを得ることができません。markers_typesmarkers.type_idmarkers_types.id

これが私のものmap_model.phpです:

class Map_model extends CI_Model{
    ...
    function get_coordinates(){
        $this->db->select('*');
        $this->db->from('markers');
        $query = $this->db->get();

        if($query->result() < 1)
            return false;
        else{
            $results = $query->result();
            return $results;
        }
    }
}

そして、ここに私のものがありますapp/controllers/map.php

$dbresults = $this->map_model->get_coordinates();

foreach($dbresults as $item){
    $marker = array();
    $marker['position'] = $item->lat.','.$item->lng;
    $marker['icon'] = base_url().'assets/img/ico/'.$item->image; // <-- I need to output here correct type image
    $marker['infowindow_content'] = $item->description;
    $this->googlemaps->add_marker($marker);
}

マーカーのタイプに応じて適切な画像を出力するように、それらをどのように混合できますか?

私は MySQL の完全な初心者なので、そのような基本的な質問を事前に申し訳ありません。試してみましたが、正しい答えを見つけることができませんでした。

4

1 に答える 1