Robert Kibet Robert Kibet - 1 month ago 5x
PHP Question

View Events by Category using PHP Code Igniter

I'm a not that advance in PHP, I need some assistance:

I have a table

with column name

I want when I click
I would get all events under
category. Same goes to

This is my views, View Image here

This is a code snippet from by views,

<div class="sell-or-buy">

<div class="icon">
<i class="et-line-briefcase"></i>

<div class="clear"></div>

<div class="content">

<h3 class="uppercase">Business</h3>

Business is always Good when you talk of a good setup. Get
the best Meetings right here.
<a href="<?php echo base_url('index.php/home/category' . $data['event_type'])?>">View</a>




I dont know how to configure my controller and my model

I am using Code Igniter 3.0 with PHP


Ok.So what i get from your question is,you had table events with event_type and you want to fetch the event data depending on event clicked/triggered.

From your posted URL,it looks like Home is your controller and category is the function and you are passing event_type to that function

<?php echo base_url('index.php/home/category/' . $data['event_type'])?>

So your controller function will go like this (I hope you are following CI user guide to define controller);

//Controller function
    function category($event_type)

    // pass the received event_type to your model
    $data['events'] = $this->event_model->get_events($event_type);

    // Pass the data to your views

// Model code goes like this
function get_events($event_type)
  **// result() returns object where as result_array() returns array**
   $query = $this->db->get_where('events',array('event_type'=>$event_type))->result();
   if (count($query) > 0)
      return $query;
      return false;

Let me know if any queries.