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

  • Home
  • SEARCH
  • 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 8442089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:45:15+00:00 2026-06-10T08:45:15+00:00

I am using codeIgniter and am really stucked on it. Here’s my model function

  • 0

I am using codeIgniter and am really stucked on it.

Here’s my model function

public function get_products_names($c_name)
{

$this->db->query('SELECT name
                  FROM products
                  WHERE category=$c_name');

return $query->result_array();
}   

And I’m calling this function from the controller class as follows

    $this->load->model('products_model');
    $data['products_categories'] = $this->products_model->get_products_names('Aata');
    echo $data['products_categories']['name'];

And its giving me the following error, I don’t know why

A Database Error Occurred

Error Number: 1054

Unknown column '$c_name' in 'where clause'

SELECT name FROM products WHERE category=$c_name

Filename: C:\wamp\www\OSW_appnsys\misystemsys\database\DB_driver.php

Line Number: 330

Any help will be highly appreciated !

  • 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-10T08:45:17+00:00Added an answer on June 10, 2026 at 8:45 am

    i may be deviating a little , but why dont you try something like this :
    (Use active records makes the query more “readable”)
    Model:

    public function get_products_names($c_name)
    {
    $this->db->select('name');
    $this->db->where('category',$c_name);
    $query = $this->db->get('products');
    if($query->num_rows) 
    return $query->result();
    return false;
    } 
    

    controller :

    $names_arr = array();
    $this->load->model('products_model');
    $result = $this->products_model->get_products_names('Aata');
    foreach($result as $r){
    array_push($names_arr,$r->name)
    }
    print_r($names_arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using codeigniter framework and I'm getting this error when I've submitted my form:
I'm using CodeIgniter and I got a model that fetches let's say all recipes
I am using codeigniter. And It really get me frustrated. I tried to remove
I am outputing a simple list of options from dynamic select menus using Codeigniter/MYSQL.
Hi I am using CodeIgniter with DataMapper and really need some help defining relationship
Background: Using CodeIgniter with this MongoDB library . This is my first go-round with
In CodeIgniter it's really tricky to combine URI segments and Query strings at the
I am getting URI segments from CodeIgniter and using them in query to an
I've been using Codeigniter for the past two years and really have become a
I'm using CodeIgniter's session library , which is really easy to access on the

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.