Welcome Guest, Not a member yet? Register   Sign In
Variable in view not the same in all pages.
#15

[eluser]Cristian Gilè[/eluser]
Quote:Hi Cristian,

if I do != TRUE instead of == TRUE

the error still stays that the ad_id variable is undefined.
and I get the message that it’s not going to the database.

My addAd function() works with no errors if the validation is set to TRUE and it also displays my ad.

You haven't set any validation rules so, according to your code, your validation test is always FALSE and the else branch

Code:
}else{
            // save data
            $ad = array('name' => $this->input->post('name'),
                            'image_url' => $full_file_path,
                            'link' => $this->input->post('link'),
                            'client_name' => $this->input->post('client_name'))

                         ;
            $ad_id = $this->adModel->save($ad);
            
            // set form input name="id"
            $this->validation->ad_id = $ad_id;
            
            // set user message
            $data['message'] = '<div class="success">add new ad success</div>';
        }
                $data['ads'] = $this->adModel->get_by_id($ad_id)->row();

will be executed. Here's why your addAd() function works.

Quote:There were functions where it displayed it correctly from the get-go and others gave me the error of undefined variable: ad_id, right?

So in those functions with that error. If I add a line before saying
$ad_id=10;

Then my ad display worksSmile

Yes, because you set $ad_id before to call the $this->adModel->get_by_id($ad_id)->row(); function, so $ad_id is not undefined.

Quote:Then my ad display worksSmile There is a big BUT though. It’s a half solution. Because if I delete that ad in my crud and add a new one, the auto-increment in my database will give the new ad an id of 11. So if I want to display that, then I have to tweak into my code again in my view file, to display that add correctly.

So I think now instead of
$ad_id=10;


I should do something like
$ad_id = 'some SQL query where it understands that if I delete ad_id = 10 in my CRUD
and put ad_id =11 in its place, it wont give any errors and will
display the image that corresponds to ad_id = 11';

Ok, that last one was roughly said, but I hope you guys understand what I mean. So should I pursue that direction more?
So now it comes down to defining $ad_id with a proper SQL query?

Your banner is associated to a client name. Right? So, probably in your db should be three tables one for banner, one for clients and one for the banner-clients association.
Code:
BANNER table:
id
name
image
link

CLIENT table:
id
name

BANNER_CLIENT table (association):
id
banner_id
client_id

When you delete a banner with id = x and from BANNER table you have to delete the corresponding row in the BANNER_CLIENT table where banner_id = x.

When you insert a banner in the BANNER table for a client x, save the id for that insert (for example y) and insert a row in the BANNER_CLIENT table with banner_id = y and client_id = x.

Now, you will pass the $id_client to the model function that query the BANNER_CLIENT table and with a join on the BANNER table you could retrieve the banner data for the client with id = $id_client.

I hope I was clear


Cristian Gilè


Messages In This Thread
Variable in view not the same in all pages. - by El Forum - 01-13-2011, 07:35 PM
Variable in view not the same in all pages. - by El Forum - 01-13-2011, 09:14 PM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:24 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:40 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:49 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:52 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 04:52 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 05:44 AM
Variable in view not the same in all pages. - by El Forum - 01-14-2011, 06:01 AM
Variable in view not the same in all pages. - by El Forum - 01-15-2011, 06:47 PM
Variable in view not the same in all pages. - by El Forum - 01-15-2011, 08:46 PM
Variable in view not the same in all pages. - by El Forum - 01-16-2011, 05:35 PM
Variable in view not the same in all pages. - by El Forum - 01-16-2011, 05:48 PM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 06:54 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 09:10 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 11:01 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 11:08 AM
Variable in view not the same in all pages. - by El Forum - 01-17-2011, 11:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB