How should echo
output following query?
My tables in MySQL database:
$query = $this->db->query('SELECT geo.order FROM Store_Information si JOIN Geography AS geo ON geo.id = si.id WHERE si.name LIKE "%' . $find1 . '%"');
My try not work:
if ($query->num_rows() > 0){
foreach($query as $val) {
$query_out = $query->row();
echo $query_out->order . '<br>';
}
}
else {
echo '0';
}
What do I do?
You need to add ->result()
in your foreach
loop:
// from the docs
$query = $this->db->query("YOUR QUERY");
foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->body;
}
You should read this guide to better understand how to use codeigniter query results.
basically this code can help:
if($query->num_rows() > 0){
foreach($query->result_array() as $row) {
var_dump($row);
}
}
and don't forget to $query->free();
your result
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.