[eluser]sore eyes[/eluser]
hi thinkigniter, many thanks for responding. Happy New Year. I'm new to codeigniter and not too much experience with php either, but I do like CI, it seems like a much better way of managing the work and I do enjoy using it.
What I want to do is cycle through records in a database, one at a time. To this end I thought of using the shop_id to select records, and then, to move onto the next record by finding the next larger shop_id and using that to display the next record. The form view, which displays one record and a 'next' button is:
Code:
<h1><?=$title?></h1>
<?=form_open('welcome/shop_insert');?>
<p>Shop ID <input type="text" name="shop_id" value="<?=$query->shop_id?>" /></p>
<p>Shop Name <input type="text" name="shopname" value="<?=$query->shopname?>" /></p>
<p>Shop Name <input type="text" name="phone" value="<?=$query->phone?>" /></p>
<p><input type="submit" value="submit" /></p>
</form>
<!--Go to the next page-->
<?php $old_shop_id=$query->shop_id ?>
<?php echo form_open('welcome/enterNextShop/'.$old_shop_id);?>
<p><input type="submit" value="goNext" /></p>
<input type="hidden" name="old_shop_id" value="$old_shop_id" />
</form>
The controller (slightly amended) is:
Code:
function enterShop()
{
$data['main'] = 'shop_view';
$data['title'] = "Shop";
$shop_id = $this->uri->segment(3);
$data['query'] = $this->MShops->getOneShop($shop_id);
$this->load->vars($data);
$this->load->view('template');
}
function enterNextShop()
{
$old_shop_id = $this->input->post('old_shop_id', TRUE);
$data = $this->MShops->getNextShop($old_shop_id);
$shop_id = $this->data->shop_id;
redirect('welcome/enterShop/'.$shop_id);
}
and the model is:
Code:
function getOneShop($shop_id)
{
$this->db->where('shop_id', $shop_id);
$this->db->select('*');
$data = $this->db->get('shop');
return $data->row();
}
function getNextShop($old_shop_id)
{
$this->db->order_by('shop_id','ASC');
$this->db->limit(1);
$this->db->where('shop_id >',$old_shop_id);
$this->db->select('shop_id');
$data = $this->db->get('shop');
return $data;
}
The problem is that the variable is not passing over. When clicking the 'next' button the old_shop_id does not pass to the controller. Also the shop_id in the 'redirect' is not being calculated.
I hope this makes sense to you and am very grateful for your consideration.