Welcome Guest, Not a member yet? Register   Sign In
just a quickie
#1

[eluser]sore eyes[/eluser]
hi, the controller function is:

Code:
function enterNextShop()
    {
        $old_shop_id = $this->uri->segment(3);
        $data = $this->MShops->getNextShop($old_shop_id);
        $shop_id = $this->data->shop_id;
        redirect('welcome/enterShop/'.$shop_id);
        
    }

The model is this:

Code:
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;
    }

I wish to pull the shop_id and can't figure out what the code
$shop_id = $this->data->shop_id;
should be. I'd be grateful for a cure.
#2

[eluser]thinkigniter[/eluser]
Do you mean in...
Code:
redirect('welcome/enterShop/'.$shop_id);

If so, how do you process the $shop_id.

Then create a function in your welcome controller called...
Code:
function entershop($passed_id){
  ... process $passed_id etc. etc.

}

I hope this is what you meant!

Cheers
#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.
#4

[eluser]ray73864[/eluser]
you need to either use row() on the data, eg:
Code:
$shop_id = $this->data->row()->shop_id;
or something else in order to get it out, since you have a where clause and a limit there just using 'row()' should work fine for you.
#5

[eluser]sore eyes[/eluser]
hi ray, thanks for responding

I changed the controller to:

Code:
function enterNextShop()
    {
        $old_shop_id =3;
        $data = $this->MShops->getNextShop($old_shop_id);
        $shop_id = $this->data->row()->shop_id;
        redirect('welcome/enterShop/'.$shop_id);
        
    }

(using a constant for the old_shop_id, just to rule any prior errors) and I get an error message

Message: Undefined property: Welcome::$data line 36
Fatal error: Call to a member function row() on a non-object in C:\Program Files\xampp\htdocs\retailers\system\application\controllers\welcome.php on line 36

any ideas?
#6

[eluser]sore eyes[/eluser]
hi ray, it works! Just a slight variation:

Code:
function enterNextShop()
    {
        $old_shop_id = $this->uri->segment(3);
        $data = $this->MShops->getNextShop($old_shop_id);
        $shop_id= $data->row()->shop_id;
        redirect('welcome/enterShop/'.$shop_id);        
    }

Many thanks for your help. I'd been stuck on this for a while.




Theme © iAndrew 2016 - Forum software by © MyBB