dongyou6768 2016-01-01 22:16
浏览 40

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

I recently started coding and fairly new top php and codeigniter.

I am wondering how to echo values from db to view file if all the values are integer in db. I may be wrong in explaining, what I am trying to do is lets say I have countries in db but they are in the form of integer(id). I can echo the integer fine but how to convert it to country name?

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');
}

Model:

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

View:

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

It only echo integers as they are saved as (id)integers in 'all_properties'.

Just to show tables that were used to insert attributes in 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条回答 默认 最新

  • douqiao5543 2016-01-01 22:35
    关注

    I didn't understand your Question, at general in data bases if there is a Country class you would find parameter in it with [ code_country = (id) ] and the [ name ]

    and you would use the query as something like this

    "select name from country where id=code_contry" 
    

    and the output should be your country as a string.

    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)