I'm trying to select data from Magento database and it doesn't work. I'm getting the following error:
Uncaught Error: Call to a member function get_var()
<?php
global $wpdb;
function jal_install() {
$table_name = $wpdb->prefix . "fees";
}
$results = $wpdb->get_var("SELECT service_fee FROM $table_name WHERE max >= $amount AND min = $amount");
echo $results['service_fee'];
?>
Related
I am getting Getting Call to a member function paginate() on array error in laravel with the following code
public static function search_query($query)
{
$tokenizeitem = array();
$tokenizeitem = queryarr($query);
//$tokenizeitem = $this->bbbootstrap->tokenizeStringIntoFTSWords($item);
$sql = "SELECT * FROM snippets WHERE MATCH(snippets_name,seo_description)
AGAINST (' ";
foreach ($tokenizeitem as $w) {
$sql .= '+' . $w . '* ';
}
$sql .= "' IN BOOLEAN MODE)";
$searchdata=DB::select( DB::raw($sql))->paginate(15);
return $searchdata;
}
The error is self explanatory:
Call to a member function paginate() on array error in laravel
your following code:
DB::select( DB::raw($sql))->paginate(15);
return an array and you can't call paginate() on array. So instead of this use:
DB::table("your query")->paginate();
Laravel Raw Query Reference
i am working now cs cart framework.i am write now insert query ,Here is my code there.
if($_REQUEST['finance'] !=''){
$finance=$_REQUEST['finance'];
$data = array();
$data = $finance;
$feature_id = db_query('INSERT INTO ?:bootsgrid_pay4later_finance ?e',
$data);
echo "success";
exit;
}
but i got e response
Fatal error: Call to undefined function db_query() in
How can i fix this issue.please help me.
to list the values from db i have been using the followin code
model
function user_list_community($serviceName) {
$ipJson = json_encode($input);
$this->db->select('*');
$this->db->from('community');
//$this->db->where('user_id', $input['user_id']);
$query = $this->db->get();
$result = $query->result();
if (!empty($result)) {
$data['list_community']= $result;
$data['message'] = 'User details retrieved successfully.';
$status = $this->ville_lib->return_status('success', $serviceName, $data, $ipJson);
} else {
$data['message'] = 'Unable to retrieve.Please the user id';
$status = $this->ville_lib->return_status('error', $serviceName, $data, $ipJson);
}
return $status;
}
controller
function list_community_post(){
$serviceName = 'list_community';
$retVals = $this->user_model->user_list_community($input, $serviceName);
header("content-type: application/json");
echo $retVals;
exit;
}
the issue am facing is am getting the values but am getting error as follows. what was the wrong am doing here. can someone help me . thanks.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: input
Filename: controllers/users.php
Line Number: 57
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: input
Filename: models/user_model.php
Line Number: 67
You are getting error because $input is not defined in the code. So you should either this:
function list_community_post(){
$input='';
$serviceName = 'list_community';
$retVals = $this->user_model->user_list_community($input, $serviceName);
header("content-type: application/json");
echo $retVals;
exit;
}
or
function list_community_post(){
$serviceName = 'list_community';
$retVals = $this->user_model->user_list_community($serviceName);
header("content-type: application/json");
echo $retVals;
exit;
}
Just like it says on the tin. Your $input variable is not created anywhere, just passed as a parameter to the json_encode and user_list_community functions.
the function user_list_community($serviceName) doesn't have two arguments while you calling it with $this->user_model->user_list_community($input, $serviceName);
try function user_list_community($input, $serviceName);
And ofcourse you have to pass value for $input arguement as above said.
I have this happen all the time and I'm never quite sure why it's happening. Here is the query in my model:
$query = $this->db->query('SELECT * FROM members WHERE email = "' . $this->session->userdata('email') . '"');
return $query;
I try to output this in my view with:
foreach($query->result() as $row) {...echo $row->name, etc.}
But I get an error:
Fatal error: Call to a member function result() on a non-object ...
I ran the profiler and my query is valid and there is data in the database to be pulled. So what am I do wrong?
Try this.
In your model:
function get_members()
{
$query = $this->db->query('SELECT * FROM members WHERE email = "' . $this->session->userdata('email') . '"');
return $query->result();
}
In your controller:
You should then be assigning the data from the database in your controller to your view like so.
$data['query'] = $this->yourmodel->get_members(); // Data['query'] will be turned into $query in your view.
$this->load->view('mytemplate', $data);
In your view:
foreach($query as $row) {...echo $row->name, etc.}
If you are passing the $query variable to the view, codeigniter will convert it into a keyed array if it is an object.
http://codeigniter.com/user_guide/general/views.html
Note: If you use an object, the class variables will be turned into array elements.
Edit:
In your controller:
$query = // do whatever to get the $query.
$members = array();
foreach($query->result() as $row) {
$members[] = $row;
}
//send $members to view
In view:
foreach($members as $member) {
echo $member['name']; // etc
}
I am getting this error "Fatal error: Call to undefined method CI_DB_mysql_driver::findVenueInfo()" when I try to use one of my models.
I have a view with this anchor:
echo anchor('welcome/searchVenue/' . $row->venue_id, $row->venue);
which generates a link like: http://localhost/ci-llmg/index.php/welcome/searchVenue/1
the method called is
function searchVenue()
{
$this->load->model('venues');
//get venue info
$data['info'] = $this->venues->findVenueInfo($this->uri->segment(3)); //this line generates the error
}
and the findVenueInfo function in the model (venues.php) is:
function findVenueInfo($id)
{
$data = array();
$this->db->where('id', $id);
$Q = $this->db->get('venues');
if ($Q->num_rows() > 0)
{
foreach ($Q->result() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
..but the result of this is Fatal error: Call to undefined method CI_DB_mysql_driver::findVenueInfo()
I'm probably missing something stupid, but can't get it to work! What do you think?
Are you sure your index.php file at the root of ur project have included bootstrap in proper place
Go to the end of the index.php file and include the bootstrap file just before including codeigniter.php.
Your index.php file should have its end lines look like this.
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
require_once APPPATH.'third_party/datamapper/bootstrap.php';
require_once BASEPATH.'core/CodeIgniter.php';
function findVenueInfo($id)
{
$data = array();
$this->db->select()->from('venues')->where('id', $id);<----change it to
$Q = $this->db->get();<----change it to
if ($Q->num_rows() > 0)
{
foreach ($Q->result() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
I was getting a similar error and found that in 3.0 I needed to enable query_builder in application/config/database.php
$query_builder = TRUE;