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