Welcome Guest, Not a member yet? Register   Sign In
I can not figure out how to call the function
#11

[eluser]LuckyFella73[/eluser]
You could build an array containing all needed informations
in your model. In your model get all rows of a category, send
the result to a method of your model that formats the result
and add the info "free" or not and then send the complete result
array to your controller and from controller to your view.
That way you have everything at one place (regarding your issue).

[EDIT]

Could look like this (not tested):
Code:
// MODEL:
function getCatalog($catId)
{
  // your query here
  $query = $this->db->query("YOUR QUERY");
  return $this->format_result($query);
}

private function format_result($query)
{
  $result = array();

  foreach ($query->result_array() as $row)
  {
   $result['title_or_whatever'][] = $row['title_or_whatever']; // I guess you have more infos then delivery from db

   if ($row['delivery'] > 0)
   {
    $result['delivery'][] = $row['delivery'].'%';
   }
   else
   {
    $result['delivery'][] = 'Free!';
   }
  }

  return $result;

    }
#12

[eluser]seobot[/eluser]
Thank you all for your help!

Everything was very simple: it was necessary to call the "helper" to the controller and use the "viewer" in a loop.

Code:
public function id($cat_id = NULL) {

        $data['catalog'] = $this->mCatalog->get_catalog($cat_id);

        if ($data['catalog']  == FALSE) {
            $data['error'] = "Category not found";
        } else {
            $this->load->helper('catalog_helper');
            $this->load->view("vCatalog", $data);
        }

    }

View

Code:
<?php foreach ($catalog as $row): ?>

        <tr>
            <td>&lt;?=delivery($row['delivery'])?&gt;</td>

        </tr>

&lt;?endforeach?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB