php - Select data from database and give error -
i want database table row name
in error. ($query->code_airline
=> other query select database table row)
code:
<?=$this->db->get_where('ticket_code', array( 'code' => $query->code_airline ))->row()->name?>
error:
a php error encountered
severity: notice
message: trying property of non-object
filename: core/loader.php(679) : eval()'d code
line number: 48
if want use as:
<?php //this line 49 $ca = echo $query->code_airline; $query_tc = $this->db->get_where('ticket_code', array( 'code' => $ca ))->row(); echo $query_tc->name; ?>
have 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 line 52 echo $row->name; ?>
i have error above php code:
a php error encountered
severity: notice
message: trying property of non-object
filename: core/loader.php(679) : eval()'d code
line number: 52
you don't echo in variable assignment
$ca = $query->code_airline; //no echo here!
also, believe you're doing wrong in calling $query->code_airline, didn't provide code i'm guessing.
suggestion: chaining nice feature can confusing, if written one-liner. first of all, write in full, can "compact" code later if feel so; keep in mind readability , maintenability also:
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca)); // $ca value assigned above. make sure you're calling $query->code_airline correctly, per suggestion. $row = $query_tc->row(); echo $row->name;
update: might want sure there result.
$query_tc = $this->db->get_where('ticket_code',array('code'=>$ca)); // $ca value assigned above. make sure you're calling $query->code_airline correctly, per suggestion. if ($query_tc->num_rows() > 0) { $row = $query_tc->row(); echo $row->name; } else { //do else }
Comments
Post a Comment