codeigniter,variables,model-view-controller,undefined , Undefined variable, how to retrieve data from database in codeigniter?

Undefined variable, how to retrieve data from database in codeigniter?


Tag: codeigniter,variables,model-view-controller,undefined

My model is:

function get_all_pages()

             $query= $this->db->query("SELECT Title FROM news");
             return $query->result_array();

My view is:

   <table cellpadding="0" cellspacing="0">

        if(!empty($content)) {
            foreach ($content as $content1)

                <td align="left"><?php echo $content1['Title']; ?></td>


        <?php }} else{?>
                <td align="center" colspan="4"><?php echo "No Record Added Yet!!!";?></td>
        <?php }?>

My controller is:

public function manage_news() 
$result_nb = $this->users_model->get_all_pages();
        $data['content'] =  $result_nb; 
        $data['page_title']="Manage Pages";

I am using codeigniter. my exact error is:

Call to undefined method users_model::get_all_pages()

how can i fix this error? i want the title row data to appear in a table (from the db)


Q: use Correct naming structure for CI? Which version do u use?

Filename models/user_model.php

Examples (for demo purpose)


class User_model extends CI_Model {

 // example one
 function get_all_pages() {

  $query =  $this->db->query("SELECT Title FROM news")->result_array();
  return ( is_array($query) && sizeof($query) > 0 ? $query : FALSE);

 // example second
 function get_all_pages_second() {

  $data = FALSE;
  $query =  $this->db->query("SELECT Title FROM news");

  if ($query->num_rows() > 0){
   $data = $query->result_array();


 return $data;


 // example third
 function get_all_pages_third() {

  $data = FALSE;
  $query =  $this->db->select('Title')->get('news');

  if ($query->num_rows() > 0){
    $data = $query->result_array();

  return $data;




codeigniter session object expired availability

This might be a silly question. Once a user has been logged in, if session expires I want to redirect him to a "lockscreen" instead to a "login" page. I want to send to the lockscreen some session data (like img-src and loginname) So, here's the question. Does session object...

post serialized data through using jquery load method in codeigniter

Here is my code. <form id='user'> <label for="name">Name :</label> <input type="text" id="name" name="name"/> <label for="email">Email :</label> <input type="text" id="email" name="email"/> <input type="submit"/> </form> <div id="output"></div> jQuery: $('#user').on('submit',function(event){ event.preventDefault(); var data=$(this).serialize(); adddetails(data); }); function adddetails(data){ var url='http://localhost/projectname/index.php/users/adddat';...

Setting session variable after destroying previous session

Why isn't the session variable value available on the second page load when I click the "Fake Login" link? class Fake_login extends CI_Controller { function __construct() { parent::__construct(); echo $this->session->userdata('session_id') . '<br>'; // First Page Load: ee3c7c5da6e465605cd57ad699aacdb3 // Second Page Load: c82adf312f123d56e3b7b6ab5ec6cafa echo $this->session->userdata('variable') . '<br>'; // First Page Load:...

Codeigniter Form Validation Rule for match (password)

I am trying to write Form validation rules in my Controller to submit Change Password form in which I am checking the old password too. I am getting the old password(current) from db and placing it in a hidden input field. My Rules are simple and are given below $config=array(...

Javascript: Resetting variable value created by form

I've created a form whereby the user enters details which are stored in variables or calculated depending on user entry. When clicking the button, a message will be displayed showing a message with the cost variable. The form clears but the message remains. The problem I have is that the...

jQuery - Increase integer by using arrays content as the variable name

Okay. This might be a little bit difficult to explain. Let's just say I have three variables in JavaScript window.seconds = 0; window.minutes = 0; window.hours = 0; and also three anchor tags in HTML <a id='seconds_plus' href=''>Increase seconds</a><br> <a id='minutes_plus' href=''>Increase minutes</a><br> <a id='hours_plus' href=''>Increase hours</a><br> Each time a...

read more function with codeigniter

i am trying to create a readmore function in codeigniter where the readmore link will be linked to a controller which would show all the data about that particular id....i am kind of confused on how to go about it... i tried... <?php $research_detail_url = site_url()."/research/research_details"; //echo json_encode($research) if($research) {...

using if else with codeigniter return value

I am using codeigniter framework for one of my inventory management systems. I prefer using php due to its variable functionality which makes things easier. So I am trying to get the username from session and then check the database for the level of the user and accordingly he should...

Get variable *value* instead of variable itself

Look at this code: <button id="button">Test</button> <button id="button2">Test</button> <script> button = document.getElementById("button"); button2 = document.getElementById("button2"); var x = 5; button.onclick = function() { alert(x); } var x = 10; button2.onclick = function() { alert(x); } </script> When I click on both of the buttons, I get 10 as result. But...

PS pipe WorkingSet as variable

I have this which gives me the WorkingSet memory usage I'm after: $mem=Get-Process spiceworks | Select-Object Name,@{Name='WorkingSet';Expression={($_.WorkingSet/1KB)}} But I'm looking to only have the actual amount as the variable so I can then work with that to monitor it. I want to set it so it alerts me if it...

How to modify CodeIgniter calendar to handle multiple events per day?

I am creating a calendar without jquery calendar plugin. I could retrieve the data which is in the database to the calendar. But when there are multiple data per day only one data comes to the calendar view. I want it to be like this when there is multiple data....

REST API with token based authentication

I want to develop a web site with AngularJS. On the backend side I will use Codeigniter REST framework. I have some security issues and I don't want to start developing without fixing them on my mind. I don't want to use something like api key because it will be...

XSLT filePath with document as variable

I try to use a variable in the filePath, but it isn't working: BodyPart filePath="C:\\FileOutEmail\\($vpDocNr).xml" content-type="" content-id="" content-disposition="" multipart-type="" I also tried with the whole path in a variable without results: BodyPart filePath='$bestand' content-type="" content-id="" content-disposition="" multipart-type="" Is this possible, what is the right syntax?...

Is there any way of protecting a variable for being modified at runtime in C?

I was wondering if there is any way of protecting a variable for being modified once initialized (something like "constantize" a variable at runtime ). For example: #include <stdio.h> #include <stdlib.h> int main(void) { int v, op; scanf( "%d", &op ); if( op == 0 ) v = 1; else...

Associative array turned into where OR clause in Codeigniter

using CI I'm trying to set up query with three parameters: user_id, content_type and content_id in which content_id is array of IDs. So I need to get up with something like this: SELECT name FROM content WHERE user_id = 2 AND content_type = file AND (content_id = 4 OR content_id...

Very weird behavior when using “var” keyword in an ajax request

I've been worrying about this for a while and I can't realize what's really happening. Explanation in code comments. There are 2 versions of an application, one of them throws weird results and the second one does the expected work. var id = "test1"; $.post("", {"data": "data"}, function(a) { alert(id);...

How to extract first letters of dashed separated words in a bash variable?

I would like to extract the first letter of dashed separated words value of my bash variable, like this: MY_TEXT=this-is-my-custom-text I would like to create a second variable like this: MY_INITIALS=timct...

gnuplot - get errors on fit parameters, get fit output values as variables, print variable to screen

Initial Question (Partially Answered) I am using gnuplot's fitting routines to fit a function to some data, and extract a "characteristic decay time constant". (I call this parameter d in my fitting function.) I have used the script code set fit quiet to prevent reams of text being printed to...

How to call this function for every controller in codeigniter

My situation is that, I have 20 controllers in my website, where I have a function like this. $this->lang->load("main", $this->session->userdata("lang_code")); How can I load this function in all the 20 controllers without adding it individually to the __constructor of every controller?...

Array in Foreach (CodeIgniter)

I want to use array in foreach loop but failed, here is my code: foreach($this->db->get_where('mytable', array('result' => '1 or 2', 'id' => 'foo'))->result_array() I think 'result' => '1 or 2'piece has a problem but I couldn't find out how can I use array in this kind of foreach. I want...

Delphi - Use a string variable's name in assignfile()

Is it possible to use a variable in the assignfile command? Eg. f : Textfile ; sFile : string ; {contains 'MyFile.txt' as content} ... cFileDir = 'C:\Users\User\Desktop\Data Engine\Data\Country' ; ... Assignfile(f, cFileDir + '\' + sFile) ; ... I appreciate your help very much. if it's unclear I'll edit...

How generate hyperlinks for news show in codeigniter

i created a news panel where we use this code for displaying news : <marquee direction="up" > <?php $query = $this->db->get('news'); foreach ($query->result() as $row) { echo $row->news; echo $row->urladdress; echo '<br/>'; } ?> </marquee> where it show correct , all data get fetched and run marquee good , but...

SQL Repeated Condition in Two Tables

I am a beginner to SQL, and I am having trouble getting rid of repeated code. I have a condition "AccountId=20" that I use twice in a SQL query. The SQL looks something like: DELETE FROM Table_A WHERE FunctionId IN (Select FunctionId FROM Table_B WHERE AccountId=20); DELETE FROM Table_B WHERE...

how to multiply two column names using codeigniter validation rule

I have three columns.The product of two columns get into third column name income_amount using codeigniter validation rule.the first column is crop_quantity and the second is per_rate controller $this->form_validation->set_rules('crop_quantity', 'Crop Quantity', 'required|numeric'); $this->form_validation->set_rules('per_rate', 'Per Rate', 'required|numeric|callback_get_product'); $this->form_validation->set_rules('income_amount', 'Income Amount', 'required|numeric');...

String concatenation not working in HTML declaration of TABS through PHP variables [closed]

The below code is not showing similar results as other one : <?php $week = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $k=0; while ( $k<= 6) { $t=$k+1; echo "<li>"; echo "<a href=#panel-".$t." data-toggle='tab'>".$week[$k]; echo "</a></li>"; $k+=1; } $a=1; echo '<div class="tab-content"> <div class="tab-pane" id="panel-"'.$a.'> <div class="alert alert-info" role="alert"> <a href="#" class="alert-link">'.$week[$a].'Bazaars</a> </div>'; ?>...

How to add support gd library to server

I have applied following code. But didn't find any solution. How I can add support gd library to server. public function addreqdoctor() { if($_FILES['userfile']['name']){ $ext = end(explode(".", $_FILES['userfile']['name'])); $new_name = time()."_".rand(1,10000).'.'.$ext; $basic['picture'] = $new_name; $config['upload_path'] = './doctors/'; $config['allowed_types'] = 'gif|jpg|png'; $config['file_name'] = $new_name; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) {...

Call known function (with parameters) in class whose name is defined by string variable

I have a bunch of classes of various names and each has a performLogic function that accepts a number of preset parameters (always the same): public final class DoSomeAction extends SetupAction { public void performLogic(param1, param2... I want a way where I can call it like this: String actionName =...

Unable to connect to your database server using the provided settings in Codeigniter

Actually I'm trying to configure my codeigniter live file to localhost. I have, created a database called test_bs then imported the tables Then change the base_url like $config['base_url']=http://localhost/gu_ci/'; and $config['index_page']='index.php'; in config.php And then did a change on database.php,Which contains $active_group = 'default'; $active_record = TRUE; $db['default']['hostname'] = 'localhost'; $db['default']['username']...

How to check for a variable name using a string in Python?

For simplicity I'm try to do this. spam = [1,2,3] stuff = [spam] x = input() if x in stuff: print(True) else: print(False) As it runs: >>> spam False Of course it doesn't print 'True' because the string 'spam' is not equal to the variable spam. Is there a simple...

Having two arrays in variable php

i've this code, i'm trying to explode my date e.g "04 June 2015" to have the day and the month in other 2 variables, but i have all in a method, with an array, is it possible, my code doesn't work, it writes "Array[0]" why? while ($i < $number) {...

Run 3 variables at once in a python for loop.

For loop with multiple variables in python 2.7. Hello, I am not certain how to go about this, I have a function that goes to a site and downloads a .csv file. It saves the .csv file in a particular format: name_uniqueID_dataType.csv. here is the code import requests name =...

Maya MEL variables declaration and initialization

Is it obligatory in MEL to initialize variables and especially strings when you declare them? I know that it is not necessary to initialize string arrays: string $buffer[]; $buffer[0] = "abc"; But what about strings and other variable types? Is it acceptably: string $str; $str = "abc"; Or should always...

Cron job with CodeIgniter using wget

I am pretty new to setting up cron jobs. What I've done so far is set one up to run every 5 minutes using the following script: */5 * * * * wget -q localhost:8888/example/index.php/controller/function When I run just the wget part from the command line, it works perfectly. But...

Group by date mysql and codeigniter

I have table like this: date_time value 2015-06-20 10:00:00 10 2015-06-20 9:00:00 6 2015-06-21 6:00:00 5 2015-06-22 11:00:00 12 2015-06-22 10:00:00 11 2015-06-23 4:00:00 20 I want to get the total value of each date Currently I have this on CodeIgniter but is not working: $this->db->group_by('date_time'); $query = $this->db->get('table_a'); Any...

jquery sortable - gives empty array in response

I am using jquery ui sortable for my codeigniter website but when i am sorting data it will give me empty array in console. please check and let me know my mistake. <script> $(document).ready( function() { $("#sortme tbody").sortable({ update : function (event, ui) { // console.log(ui); serial = $('#sortme tbody...

Undefined local variable post

I write this code: <% @user.posts.each do |post| %> <%= render 'post', locals: { post: post, user: @user} %> <% end %> Then in _post.htm.erb I write follow code: <div class="post-title"> <img src="<%= @user.avatar.url%>" class="img-rounded post-image"> <h4 id="post-name"><%= @user.first_name + ' ' [email protected]_name %> </h4> <div id="post-date"><%= post.created_at.strftime('%d %b -...

Problems with Flash 8 (AS2), Timelines, and Variable Scopes

Okay, so trying to not post 5 pages of information, I'll start with the following: In a movie clip, I have 3 keyframes. I'm trying to edit a textbox on each frame, but I've found previously that only the text box in the current frame is accessible. In an attempt...

Where are the local variables of an Android app stored?

The Dalvik Virtual Machine (DVM) has a register-based architecture, as opposed to the Java Virtual Machine (JVM) which is stack-based. So I assume that the local variables of an Android app are stored in the registers. Am I correct? If not, please correct me. If yes, what kind of memory...

calling string as variable in python

I created a class called SignalParam in python containing different properties (frequency, voltage, time, etc) I would like to create many instances of this type vars()['Segment'+str(segment_number)] = SignalParam() this line is working and i can create variables "Segment1", "Segment2", .... My question is: i would like to call those variabes...

subtracting from multiple variables at a time

So recently I've ben interested in learning python, and I got the "Think python" last Christmas. Unfortunately I haven't had the time to really get into it because of my exams. Even though I the book was written for python 2 I decided to use python 3.4.3 anyway. This does...

Compiler modifying a variable without adressing it

In my program I found that when asssigning a variable to another, modifying the first one, also modifies the second. Example: using System; using System.Collections.Generic; using System.Windows.Forms; namespace Dict_test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void TestButton_Click(object sender, EventArgs e) { Dictionary<string,...

How to get value from property in BeanShell (jmeter)

I have got several thread groups. I want to use variable from the first group. In second group this var should be used in BeanShell. So: in first thread group I created BeanShell Assertion with this code: ${__setProperty(erroriden, ${erroriden1})}; In second thread group I have BeanShell pre-processor. If has line...

SQL Multiple LIKE Statements

I'm currently working on a report that shows me all post codes covered by our sales team. Each team covers over 100 post codes. What i would like to do is create a report that brings back the clients within the post code. Currently my code looks like this. SELECT...

Add custom error messages to CI validation_errors()

There's a way to add custom error messages to CodeIgniter validation_errors();? Example, if I wanted a field with a 123456 value, and the user inputs 12345 I'd want to set a message to say: The number 6 is required! And any other custom rules I may want to add. Like...

How can I use a variable to get an Input$ in Shiny?

I am new to R and I am creating a shiny application to read a csv and filter data. I am reading the csv file, then creating dropdowns with a loop using the column names and the unique values: output$dropdowns <- renderUI({ if (is.null(x())) { return(NULL) } lapply(1:ncol(x()), function(i) {...

When I click to the next page on pagination,it goes to 404 error in codeigniter

In my News.phpcontroller,i'm having the below code: public function index() { $data['title'] = 'Database Details'; $config = array(); $config['base_url'] = base_url("news/index"); $config['total_rows'] = $this->news_model->record_count(); $config['per_page'] = 5; $config['uri_segment'] = 3; //$config['use_page_numbers'] = TRUE; // $config['page_query_string'] = TRUE; $choice = $config["total_rows"] / $config["per_page"]; $config["num_links"] = round($choice); $this->pagination->initialize($config); $page =...

Codeigniter Select JSON, Insert JSON

I have very simple users database: user_id, user_name, user_email My model this: class Users extends CI_Model { private $table; private $table_fields; private $table_fields_join; function __construct() { parent::__construct(); $this->table = 'users'; $this->table_fields = array( $this->table.'.user_id', $this->table.'.user_name', $this->table.'.user_email' ); $this->table_fields_join = array(); } function select(){ $this->db->select(implode(', ', array_merge($this->table_fields, $this->table_fields_join)));...

PHP / JavaScript: How to pass variable from one page to another

I am new to PHP and hope someone can help me with this. I have a page (index.php) where users can select a language. If no language is selected than the page URL is just index.php which defaults to English. If they select a language than the page gets reload...

Best way to serialize a JOIN SQL query to JSON

I can't find a good title for my question. I'm doing a Restful API /JSON My problem is: I have got two tables: Product: id, name Prices: id_product, price Product 1--* Prices (One product have got multiples prices) So, If I want to export the next information in JSON products:...

PHP Define var = one or other (aka: $var=($a||$b);)

Is there a way to define a php variable to be one or the other just like you would do var x = (y||z) in javascript? Get the size of the screen, current web page and browser window. var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight...