KaHeL
KaHeL

Reputation: 4371

Database query returns strange values for display in codeigniter

I'm having a hard time again in my query for codeigniter. First of all I read about this tutorials to base the work I'm doing in current: http://ellislab.com/codeigniter/user_guide/tutorial/news_section.html

Now what I do is something like this for the model function for my database:

public function get_events()
    {
            $id = $this->session->userdata('id');
            $this->db->flush_cache();
            $this->db->select('event_id');
            $this->db->select('event_name');
            $this->db->select('event_date');
            $this->db->select('event_time');
            $this->db->select('event_count');
            $this->db->select('event_max');
            $this->db->select('status');
            $query = $this->db->get_where('event_details',array('bar_id' => $id));
            return $query->row_array();
    }

And now to pass the values in my controller I use this line of code:

$data['events'] = $this->events_model->get_events();

And for the view I use this:

<table class="events_list">
<?php foreach ($events as $events_info): ?>
    <tr>
        <td>
            <input type="hidden" value="<?php echo $events_info['id'] ?>">
            <?php echo $events_info['event_name'] ?>
        </td>
        <td>
            <?php echo $events_info['event_date'] ?>
        </td>
        <td>
            <?php echo $events_info['event_time'] ?>
        </td>
        <td>
            <?php echo $events_info['event_count'].'/'.$events_info['event_max'] ?>
        </td>
        <td>
            <?php echo $events_info['status'] ?>
        </td>
    </tr>
<?php endforeach ?>
</table>

I'm supposed to get a return of:

(hidden)1 | Silverstein Concert | 2012-07-11 | 18:00:00 | 0/500 | 1

but instead I get a return of

1 | 1 | 1 | 1/1 | 1 

Well I haven't displayed the whole return but this is supposed to have a 7 rows which all has a strange 1 character returns (next row contains full of S). I can't tell where the problem really is since when I use

$data['test']=$data['events']['event_name'];

in my controller and displays it on my view the event name displays but only the first row data is repeating 7 times. Well I just need to solve this so that I can move on. Thanks!

Upvotes: 1

Views: 281

Answers (1)

air4x
air4x

Reputation: 5683

If you can get the event name using $data['events']['event_name'], it means $data[events] contains a single row. Remove the foreach from your view and try with $events['event_name'], $events['event_date'] etc.

row_array returns only a single row from your result set.

Upvotes: 2

Related Questions