Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:31:26+00:00 2026-06-10T05:31:26+00:00

i am doing some practice on the codeigniter to retrieve the data from database

  • 0

i am doing some practice on the codeigniter to retrieve the data from database and i am success to do this.but the problem arise when i want to fetch data of a specific field.
to retrieve the specific value i am using the following URL on my local host:

localhost/codeigniter/index.php/news/view/city-news

where news is controller,view is method of controller and city-news is argument.

Here is my code of controller:

public function view($slug)
    {

        $data['news'] = $this->news_model->get_news($slug);//here i am getting the slug value.
                if (empty($data['news_item']))
            {
        show_404();
            }

        $data['title'] = $data['news_item']['title'];

        $this->load->view('templates/header', $data);
        $this->load->view('news/view', $data);
        $this->load->view('templates/footer');
    }

this method calls the method get_news($slug) of model news_model.here is the code of this method:

public function get_news($slug = FALSE)
   {

    if ($slug === FALSE)
    {
        $query = $this->db->get('news');
        return $query->result_array();
    }
    echo $slug;//here is i m also getting the slug value.
    $query = $this->db->get_where('news', array('slug' => $slug));//i think this is not working properly
    print_r($query->row_array());die;//now i am getting values here.   
    return $query->row_array();
   } 

but still my view shows “404 page not found”. my view code is:

<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
?>

Now please tell me where i am going wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:31:27+00:00Added an answer on June 10, 2026 at 5:31 am

    your error is you are setting $data['news'] and testing $data['news_item'] :

    $data['news'] = $this->news_model->get_news($slug);//here i am getting the slug value.
    
    if (empty($data['news_item'])) // <=== HERE IS THE ERROR
    {
        show_404();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing a some practice questions for exam tomorrow can't figure out this one What
I'm doing this in C#, but, I guess, it isn't language specific problem... I've
I am just doing some practice from one of my books, and I was
I encountered this problem when doing some enthusiastic programming. The problem can be expressed
I was doing some practice problems in Coding Bat , and came across this
I am doing some asynchronous data fetching, and I need to do this in
im doing some practice sql problems one of the questions is: Prepare a shipping
I'm doing some programming practice right now by trying to sort a 2D array
I've been doing some research on whether what best practice is regarding the use
Hey there, I'm doing some queries to a MySQL database that involves some user-input..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.