1

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!

7
  • 1
    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. Commented Oct 28, 2012 at 5:09
  • what do you get when you write print_r($events) before foreach ? Commented Oct 28, 2012 at 5:15
  • oh wait I'll try your suggestions. :) Commented Oct 28, 2012 at 5:28
  • Oh you're both correct I only get 1 row. Array ( [event_id] => 16 [event_name] => Silverstein Concert [event_date] => 2012-07-11 [event_time] => 18:00:00 [event_count] => 0 [event_max] => 500 [status] => 1 ). But well it's supposed to return 7 rows. How does this happen? Commented Oct 28, 2012 at 5:31
  • Check the row_array documentation. Commented Oct 28, 2012 at 5:34

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.