codeigniter dynamic combobox - php

trying to make some dynamic combobox and found some troubles..
here's the code
controller
$this->load->model('main_model');
$data['sales'] = $this->main_model->getSales();
$this->load->view('dashboard_view',$data);
the model
$this->db->select('*');
$this->db->from('salesman');
$this->db->where('cabangid',$cabangid);
$this->db->order_by('salesmanid','ASC');
$array_keys_values = $this->db->get();
foreach ($array_keys_values->result() as $row)
{
$result[0]= '- sales-';
$result[$row->salesmanid]= $row->description;
}
return $result;
the view
<div id="sales" style="width:250px;float:left;">
sales: <br/>
<?php
echo form_dropdown("salesmanid",$sales,"","id='salesmanid'");
?>
the error are like these..
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: sales
Filename: views/dashboard_view.php
Line Number: 14
and
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331
any help would be appreciated..:D

Related

Need advice to make php server side Datatables work properly

There's something weird going on with server-side Datatables from this: https://github.com/n1crack/Datatables.
Don't understand what's going on, i do exactly the same thing as the examples but it simply doesn't work. According to the "where" example https://github.com/n1crack/Datatables/blob/master/public/examples/where/ajax.php, look how simple it should be:
$dt = new Datatables(new MySQL($config));
$dt->query("Select film_id as fid, title, description from film where film_id > 47 and film_id < 83");
echo $dt->generate();
My code:
$config = [ 'host' => 'localhost',
'port' => '3306',
'username' => 'root',
'password' => '',
'database' => 'sys_db_gincana' ];
$dt = new Datatables( new MySQL($config) );
$dt->query("
SELECT seen, id, name, cep, date_format(created,'%d/%m/%Y %h:%i:%s') as created
FROM user
");
echo $dt->generate();
Now look at what my js console prints from my ajax:
A PHP Error was encountered
Severity: 4096 Message: Argument 1 passed to
PHPSQLParser\builders\WhereBuilder::build() must be of the type array,
boolean given, called in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\greenlion\php-sql-parser\src\PHPSQLParser\builders\SelectStatementBuilder.php
on line 74 and defined Filename: builders/WhereBuilder.php
Line Number: 112
A PHP Error was encountered
Severity: Warning Message: Invalid argument supplied for
foreach() Filename: builders/WhereBuilder.php Line
Number: 114
A PHP Error was encountered
Severity: 4096 Message: Argument 1 passed to
PHPSQLParser\builders\WhereBuilder::build() must be of the type array,
boolean given, called in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\greenlion\php-sql-parser\src\PHPSQLParser\builders\SelectStatementBuilder.php
on line 74 and defined Filename: builders/WhereBuilder.php
Line Number: 112
A PHP Error was encountered
Severity: Warning Message: Invalid argument supplied for
foreach() Filename: builders/WhereBuilder.php Line
Number: 114
Fatal error: Call to a member function
fetch_assoc() on a non-object in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\ozdemir\datatables\src\DB\MySQL.php
on line 40
And if if i change the query to:
$dt = new Datatables( new MySQL($config) );
$dt->query("
SELECT seen, id, name, cep, date_format(created,'%d/%m/%Y %h:%i:%s') as created
FROM user
WHERE approved = 0 and canceled = 0
");
echo $dt->generate();
the error changes:
A PHP Error was encountered
Severity: Warning Message: array_merge(): Argument #2 is
not an array Filename: src/Datatables.php Line Number:
47
Fatal error: Call to a member function
fetch_assoc() on a non-object in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\ozdemir\datatables\src\DB\MySQL.php
on line 40
Well, the library is a bit new (january 2015), i wonder if someone that had success using it could help me.
Regards
The problem in the WhereBuilder comes from the PHPSQLParser, can you test the latest version from https://github.com/greenlion/PHP-SQL-Parser? It seems to be a simple SQL statement, so actually it should work. I have moved your issue to GitHub, please follow the changes there.

Codeigniter : Retriving data between two dates from database

How can I retrieve data from the database by querying records between two dates using codeigniter?
Here is my code :
function date_employee_details($id,$fdate,$sdate)
{
$this->db->select('*');
$this->db->where('user_id',$id);
$this->db->where('dates >=',$fdate);
$this->db->where('dates <=',$sdate);
return $this->db->get('attendance');
}
but i got an error :
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: fdate
Filename: models/admin.php
Line Number: 726
thanks

A PHP Error was encountered Severity: Notice Message: Undefined index: elements_id Filename: views/showdetail.php Line Number: 17

A PHP Error was encountered
Severity: Notice
Message: Undefined index: elements_id
Filename: views/showdetail.php
Line Number: 17
Help me please!
Error on server openshift but Run on localhost no error.
How to fix?
Do this with each variable
$elements_id=isset($row['elements_id'])?$row['elements_id']):'';
You are trying to use the vale of the index of the array without checking first if is set
<?php
print_r($dataelements);
foreach ($dataelements as $row) {
$elements_id =$row['elements_id'];
$elements_number = $row['elements_number'];
$elements_name = $row['elements_name'];
$elements_principle = $row['elements_principle'];
$elements_standard = $row['elements_standard'];
$elements_indicator = $row['elements_indicator'];
}
?>

Codeigniter autoload library with parameters

I'm using FX.php together with Codeigniter to access a Filemaker DB. Library and config file are autoloaded in config/autoload.php.
This setup works perfectly well on my development machine (OS X, PHP 5.3.14). However, when I run the project on our dev server (Ubuntu Precise, PHP 5.3.10), it doesn't work. There seems to be an issue with the config parameters not being passed to the library. I get the following error messages:
Severity: Notice
Message: Undefined index: dataServer
Filename: libraries/CIFX.php
Line Number: 9
Severity: Notice
Message: Undefined index: dataPort
Filename: libraries/CIFX.php
Line Number: 9
Severity: Notice
Message: Undefined index: dataType
Filename: libraries/CIFX.php
Line Number: 9
Severity: Notice
Message: Undefined index: dataURLType
Filename: libraries/CIFX.php
Line Number: 9
My libraries/CIFX.php file looks like this:
require('FX.php');
class CIFX extends FX {
function __construct ($params = array())
{
parent::__construct($params['dataServer'], $params['dataPort'], $params['dataType'], $params['dataURLType']);
}
}
?>
My config/CIFX.php file looks like this:
$config['dataServer'] = '192.168.1.10';
$config['dataPort'] = '80';
$config['dataType'] = 'FMPro7';
$config['dataURLType'] = '';
$config['dbuser'] = '';
$config['dbpassword'] = '';
According to the Codeigniter manual, this should be working.
Any help much appreciated!
you need to be Passing Parameters When Initializing Your Class
$params = array(
'dataServer' => $this->config->item('dataServer');,
'dataPort' => $this->config->item('dataPort');
);
$this->load->library('CIFX ', $params);

Select data from database and give error

I want get from database table row name but in it i get error. ($query->code_airline => is other query as select from database table row)
code:
<?=$this->db->get_where('ticket_code', array( 'code' => $query->code_airline ))->row()->name?>
error:
A PHP Error was encountered Severity: Notice Message: Trying
to get property of non-object Filename: core/Loader.php(679) :
eval()'d code Line Number: 48
If want use it as:
<?php //This is line 49
$ca = echo $query->code_airline;
$query_tc = $this->db->get_where('ticket_code', array( 'code' => $ca ))->row();
echo $query_tc->name;
?>
have this error:
Parse error: syntax error, unexpected T_ECHO in
D:\xampp\htdocs\system\core\Loader.php(679) : eval()'d code on line 49
How can fix it?
Update:
i use as:
<?php
$ca = $query->code_airline;
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca));
$row = $query_tc->row(); //This is line 52
echo $row->name;
?>
i have this error with above php code:
A PHP Error was encountered Severity: Notice Message: Trying
to get property of non-object Filename: core/Loader.php(679) :
eval()'d code Line Number: 52
You don't ECHO in a variable assignment
$ca = $query->code_airline; //no echo here!
Also, I believe you're doing something wrong in calling $query->code_airline, but you didn't provide your code so I'm just guessing.
Suggestion: chaining is a nice feature but can be confusing, especially if written as one-liner. First of all, write it in full, you can "compact" your code later if you feel so; keep in mind readability and maintenability also:
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca));
// $ca is the value assigned above. Make sure you're calling $query->code_airline correctly, as per my suggestion.
$row = $query_tc->row();
echo $row->name;
UPDATE:
you might want to be sure that there are actually any result.
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca));
// $ca is the value assigned above. Make sure you're calling $query->code_airline correctly, as per my suggestion.
if ($query_tc->num_rows() > 0)
{
$row = $query_tc->row();
echo $row->name;
}
else
{
//do something else
}

Categories