Welcome Guest, Not a member yet? Register   Sign In
View is showing only first letter of the result value
#1

[eluser]Unknown[/eluser]
I am new to CI and doing my first project on my local machine using WAMP.

The results displayed on my view page show only the first letter of the result value.
Can anyone explain why the whole value is not showing up?

The result of my view shows this:

Code:
Array ( [result] => Array ( [shipping_id] => 8 [shipping_name] => Priority Mail [shipping_alias] => PRTM [shipping_default] => 0 ) [title] => Test Title )

Test Title
You returned:
8

P

P

0

The view code looks like this:
Code:
<body>

<h1>&lt;?php echo $title; ?&gt;</h1>
You returned:
&lt;?php foreach ($result as $key =>$res){ ?&gt;
    <h3>&lt;?php echo $res['shipping_id'] ?&gt;</h3>
    <br/>
&lt;?php }  ?&gt;
<div id="ordersList"></div>


&lt;/body&gt;

This is what my controller look s like:
Code:
class Orders extends Controller {

    function Orders()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->model('orders_model');
        $data['result'] = $this->orders_model->getTestData();
        $data['title'] = 'Test Title';
        print_r($data);
        $this->load->view('orders_view',$data);
    }
}

This is what my model looks like:
Code:
class Orders_model extends Model{

    function Orders_model(){
        parent::Model();
    }
    
    function getTestData(){
        $data = array();
        $q = $this->db->get('shipping');
        if($q->num_rows() > 0){
            $data = $q->row_array();
        }
        $q->free_result();
        return $data;
    }
}
#2

[eluser]Unknown[/eluser]
Fixed my issue. Evidently, I wasn't working with an array.

changes in View:
Code:
&lt;?php foreach ($result as $val){ ?&gt;
    <h3>&lt;?php echo $val['shipping_id']; ?&gt;</h3>
    <br/>
&lt;?php }  ?&gt;

changes in Model:
Code:
function getTestData(){
        $data = array();
        $q = $this->db->get('shipping',5);
        if($q->num_rows() > 0){
            foreach($q->result_array() as $row){
                $data[] = $row;
            }
        }        
        $q->free_result();
        return $data;
    }

I know this is a little different form the first version which was only one array, where this is an array of arrays.




Theme © iAndrew 2016 - Forum software by © MyBB