Hello!
I have a table called Events and one of the colums is called "country". I want to be able to query events based on the user country. So eventID #1 might have "country" = US, CA, MX (multiple values), so if a user is from the US logs-in will see the eventID 1 , but also if a user from CA logs-in will see the same event.
I created a <select name=country[] multiple> with a list of countries. I would like to be able to select several countries and save them in a colum. I tested json_encode and serialize and it like better json_encode but I was wonderig what's your view?
so on my form i have someeting like this....
<select name="country[]" size="10" multiple>
<?php foreach ($countries as $key => $val) { ?>
<option value="<?=$key?>" <?php if (in_array($key, json_decode($event->country))) { echo 'selected'; } ?>><?=$val?></option>
<?php } ?>
</select>
my controller looks like this:
function save($id)
{
$event = Event::find($id);
$event->country = json_encode($input['country']);
$event->save();
}
my query looks like this
function getEvents() {
return 'Select * From events where country IN ($user->country) ';
}