Welcome Guest, Not a member yet? Register   Sign In
How to check if some data exists in database?
#1

[eluser]v33s[/eluser]
Hello all! I have a problem. Could someone help me?

Actually I am making articles script, method from controller:

Code:
function _viewArticle($id)
    {
        if(is_null($id))
        {
            redirect('');
        }
        else
        {
            $query = $this->show_arts->getPage($id);
            if($query->result() < 0)
            {
                show_error('There arent any articles.');
            }
            elseif($this->uri->segment(3) != $query->count_all())
            {
                show_error('That article doesnt exist.');
            }
            else
            {
                foreach ($query->result() as $row)
                {
                    $this->load->view('show', $row);
                }
            }
        }


And I have problem with This:

Code:
elseif($this->uri->segment(3) != $query->count_all())
            {
                show_error('That article doesnt exist.');
            }

How to replace the code below when I get url: /index.php/show/article/id

And article with uri segment 3 does not exist in database?

Regards.
#2

[eluser]v33s[/eluser]
OK. I`ve made it own Wink

Just like that:

Code:
elseif(!$this->show_arts->_pageExists($this->uri->segment(3))->num_rows() != 0)
            {
                show_error('That page does not exist.');
            }




Theme © iAndrew 2016 - Forum software by © MyBB