• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
just a quickie

#3
[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>&lt;?=$title?&gt;</h1>

&lt;?=form_open('welcome/shop_insert');?&gt;
<p>Shop ID &lt;input type="text" name="shop_id" value="&lt;?=$query-&gt;shop_id?&gt;" /></p>
<p>Shop Name &lt;input type="text" name="shopname" value="&lt;?=$query-&gt;shopname?&gt;" /></p>
<p>Shop Name &lt;input type="text" name="phone" value="&lt;?=$query-&gt;phone?&gt;" /></p>
<p>&lt;input type="submit" value="submit" /&gt;&lt;/p>
&lt;/form&gt;


&lt;!--Go to the next page--&gt;
&lt;?php $old_shop_id=$query->shop_id ?&gt;
&lt;?php echo form_open('welcome/enterNextShop/'.$old_shop_id);?&gt;
<p>&lt;input type="submit" value="goNext"   /&gt;&lt;/p>
&lt;input type="hidden" name="old_shop_id" value="$old_shop_id" /&gt;
&lt;/form&gt;

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.


Messages In This Thread
just a quickie - by El Forum - 12-31-2008, 12:05 AM
just a quickie - by El Forum - 12-31-2008, 06:02 AM
just a quickie - by El Forum - 12-31-2008, 07:31 PM
just a quickie - by El Forum - 12-31-2008, 08:05 PM
just a quickie - by El Forum - 01-01-2009, 04:30 AM
just a quickie - by El Forum - 01-01-2009, 10:57 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.