So the scenario is this:
I currently have a DB with TV Shows with RSS Feeds.
The feeds (TV Shows) table has ID, name, network, feed, active.
I have setup a field in the accounts table called favourites, i thought comma delimited ID’s of the TV Shows might be a good idea, but im not sure anymore.
I am currently looking to implement a controller in CI that will look at the DB in the favourites field, for eg if it was filled with 104,149,150
How can I get those ID’s to transfer into the view so I can set the values to the respective Show’s?
<?php foreach ($shows as $show) { ?>
<div class="grid_1">
<? $data = array(
'name' => $show['name'],
'id' => $show['id'],
'value' => $show['name'],
'checked' => FALSE,
);
echo form_checkbox($data); ?>
</div>
<div class="item"><?=form_label($show['name']);?></div>
<?php } ?>
The view currently outputs the TV shows in the database with a check box next to each show, what is the best way for me to set user preferences for favourites? So that I can set the values of each checkbox according to the user preference
I hope I have explained what I am trying to do well,
Thanks!
You can load a view and send variables/parameters to it as such:
EDIT:
To save favorites, I suggest creating a new table (‘favorites’) that contains a favorite_id, user_id, show_id .. perhaps a date added, maybe some other things.
In the Shows page, where the checkboxes reside, you could do the following:
This means you must send over an array called
$favoriteswhich would look something like$params['favorites']in your controller.The query to get the favorites would look something like this:
The
array($user_id)following the query is called query binding, used for security.