0

I have a php function in codeignter set up to run a query based on all the values it is given. By default, it's set up in my model like so:

function get_news($page=0, $limit=4, $offset=0, $name=0) {
    if($name == 0) {
        $query = $this->db->get('table', $limit, $offset);
    } else {
        $query = $this->db->get_where('table', array('name'=>''.$name.''), $limit, $offset);
    }
}

However when I pass a value for $name in my controller, it runs the query for $name==0

$name = "Bob";
$this->News_model->get_news($page=0, $limit=3, $offset=0, $name);

Any idea why the $name value isn't going through?

1
  • 1
    Don't call the function using $this->News_model->get_news($page=0, $limit=3, $offset=0, $name);.... use $this->News_model->get_news(0, =3, 0, $name);.... but what is the concatenation in array('name'=>''.$name.''), supposed to do? Commented Sep 26, 2014 at 21:11

1 Answer 1

2

Model

function get_news($page=0, $limit=4, $offset=0, $name=0) {
  if($name == 0) {
    $query = $this->db->get('table', $limit, $offset);
  } else {
    $query = $this->db->get_where('table', array('name'=>$name), $limit, $offset);
  }
}

use

$name = "Bob";
$this->News_model->get_news(0, 3, 0, $name);
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.