首页 文章

如何在codeigniter中将db的整数值(id)回显为db

提问于
浏览
0

我最近开始编码和相当新的顶级PHP和codeigniter .

我想知道如果db中的所有值都是整数,如何从db回显值到视图文件 . 我在解释时可能是错的,我想要做的是让我说db中有国家但是它们是整数(id)的形式 . 我可以回显整数,但如何将其转换为国家名称?

Conteroller:

public function index() {
    $data['title'] = "Dynamic Title";
    $data['details'] = $this->model_users->property_details();
    $this->load->view('headfoot/header-item', $data);
    $this->load->view('item', $data);
    $this->load->view('headfoot/footer-item');
}

模型:

function property_details(){
    $this->db->select('*');
    $this->db->from('all_properties');
    $query=$this->db->get();
    return $query; 
}

视图:

<?php foreach($details as $details): ?>
<?= $details->property_country; ?>
<?= $details->property_state; ?>
<?= $details->property_city; ?>
<?php endforeach; ?>

它只回显整数,因为它们在'all_properties'中保存为(id)整数 .

只是为了显示用于在db中插入属性的表

function getCountry(){
    $this->db->select('v_country_id,v_country_name');
    $this->db->from('vbc_country');
    $this->db->order_by('v_country_name', 'asc'); 
    $query=$this->db->get();
    return $query; 
}
function getData($loadType,$loadId){
    if($loadType=="state"){
        $fieldList='id,v_state_name as name';
        $table='vbc_state';
        $fieldName='country_id';
        $orderByField='v_state_name';                       
    }elseif($loadType == "region"){
        $fieldList='id,v_state_region_name as name';
        $table='vbc_state_region';
        $fieldName='state_id';
        $orderByField='v_state_region_name';
    }else{
        $fieldList='id,v_city_name as name';
        $table='vbc_city';
        $fieldName='state_region_id';
        $orderByField='v_city_name';
    }

1 回答

  • 0

    我不明白你的问题,一般在数据库中,如果有一个Country类,你会在[code_country =(id)]和[name]中找到参数

    你会像这样使用查询

    "select name from country where id=code_contry"
    

    并且输出应该是您的国家/地区作为字符串 .

相关问题