[eluser]riwakawd[/eluser]
Hi I just working on my model for my stores url and name. Every time I add new row in database and the refresh page will not show the updated information or any new rows.
I need it to be able to show all new and updated information.
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: store/store_list.php
Line Number: 16
Model
Code:
public function getStores() {
$this->db->select('*');
$this->db->from('store');
$this->db->where('store_id');
$this->db->order_by('url', ' asc');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return true;
} else {
return false;
}
}
View
Code:
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<form action="" method="post" enctype="multipart/form-data" >
<table class="table table-striped table-hover">
<tbody>
<?php foreach($stores as $store) : ?>
<tr>
<td><?php echo $store['name']; ?></td>
<td><?php echo $store['url'] ;?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
</div>
</div>
Controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Store extends MX_Controller {
public function __construct() {
parent::__construct();
$this->lang->load('admin/store/store', 'english');
$this->lang->load('admin/english', 'english');
$this->load->driver('cache');
if ($this->session->userdata('user_id') == true) {
return true;
} else {
redirect('admin');
}
}
public function index() {
$this->document->setTitle($this->lang->line('heading_title'));
$this->getList();
}
public function getList() {
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('text_home'),
'href' => site_url('admin/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('admin/store')
);
$data['heading_title'] = $this->lang->line('heading_title');
$data['text_no_results'] = $this->lang->line('text_no_results');
$data['text_confirm'] = $this->lang->line('text_confirm');
$data['column_name'] = $this->lang->line('column_name');
$data['column_url'] = $this->lang->line('column_url');
$data['column_action'] = $this->lang->line('column_action');
$data['button_insert'] = $this->lang->line('button_insert');
$data['button_edit'] = $this->lang->line('button_edit');
$data['button_delete'] = $this->lang->line('button_delete');
$data['button_save'] = $this->lang->line('button_save');
$data['button_cancel'] = $this->lang->line('button_cancel');
$this->load->model('admin/store/model_store');
$data['stores'] = $this->model_store->getStores();
$data['cancel'] = site_url('admin/dashboard');
return $this->load->view('store/store_list', $data);
}
}