Welcome Guest, Not a member yet? Register   Sign In
Having a Problem in fetching the results from db
#1
Wink 

Hai , Friends ...
   I am facing the problem in  fetching  the results from database ... ... the below code is working perfectly but i am not understand the code plz give  clarify .. when its where condition is depends .. if i change the page field then also working perfectly
.. what's going on i not understood help me .. Thanks .....!
[attachment=55][attachment=57][attachment=58][attachment=56]
Manikanta
Reply
#2

So many "...", so not a question...
Reply
#3

(12-29-2014, 05:31 AM)Chandini Wrote: Hai , Friends ...
   I am facing the problem in  fetching  the results from database ... ... the below code is working perfectly but i am not understand the code plz give  clarify .. when its where condition is depends .. if i change the page field then also working perfectly
.. what's going on i not understood help me .. Thanks .....!

Try some thing like this in model to get data
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Model_setting_get extends CI_Model {
    
var 
$table_store 'store';

public function 
__construct() {
parent::__construct();
}

public function 
get_stores() {
return 
$this->db->get($this->db->dbprefix .$this->table_store)->result_array();
}


There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

(12-29-2014, 05:31 AM)Chandini Wrote: Hai , Friends ...
   I am facing the problem in  fetching  the results from database ... ... the below code is working perfectly

Hi, Chandini. The code works perfectly? Because your getData function seems to have a problem in the line:
PHP Code:
$query=$this->db->get_where("pagedata"); 

According to the manual, the get_where function is used like this:
PHP Code:
$query $this->db->get_where('mytable', array('id' => $id)); 

You have to tell get_where the name of your table, and you have to give it an array to construct the where clause. I don't know the name of your table in the last attached screenshot, but suppose your table is called 'pages', so then your getData should be like this:
PHP Code:
function getData($what_page)
{
 
   $query $this->db>get_where('pages'$what_page);
 
   return $query->result()


And you would call getData like this:
PHP Code:
$data['results'] = $this->model_get->getData(array('page' => 'home')); 

If you know SQL, I think it's easier to just use the query function like this:
PHP Code:
function getData($what_page)
{
 
   return $this->db->query(
 
       'SELECT * FROM pages WHERE page = "' $what_page '";'
 
   );

With this method, you don't have to use any array, just the name of the page you want.

Ok, good luck. I hope the above helps.
Reply
#5

(12-30-2014, 08:25 AM)RobertSF Wrote:
(12-29-2014, 05:31 AM)Chandini Wrote: Hai , Friends ...
   I am facing the problem in  fetching  the results from database ... ... the below code is working perfectly

Hi, Chandini. The code works perfectly? Because your getData function seems to have a problem in the line:

PHP Code:
$query=$this->db->get_where("pagedata"); 

According to the manual, the get_where function is used like this:

PHP Code:
$query $this->db->get_where('mytable', array('id' => $id)); 

You have to tell get_where the name of your table, and you have to give it an array to construct the where clause. I don't know the name of your table in the last attached screenshot, but suppose your table is called 'pages', so then your getData should be like this:

PHP Code:
function getData($what_page)
{
 
   $query $this->db>get_where('pages'$what_page);
 
   return $query->result()


And you would call getData like this:

PHP Code:
$data['results'] = $this->model_get->getData(array('page' => 'home')); 

If you know SQL, I think it's easier to just use the query function like this:

PHP Code:
function getData($what_page)
{
 
   return $this->db->query(
 
       'SELECT * FROM pages WHERE page = "' $what_page '";'
 
   );

With this method, you don't have to use any array, just the name of the page you want.

Ok, good luck. I hope the above helps.

https://ellislab.com/codeIgniter/user-gu...eries.html

Specifically the part about "Escaping Queries"
Reply




Theme © iAndrew 2016 - Forum software by © MyBB