I have the following database table called artist_genres. I currently have a function which finds all genre_id's by artist and echo's them in an object oriented way:
<?php
$artistgenres = Artistgenres::find_all_genres_by_artist_id($_SESSION['artist_id']);
foreach($artistgenres as $artistgenre){
echo $artistgenre->genre_id."<br>";
}
?>
When the artist with id 8 logs in, and goes to this page, I would like for him to be able to update the current genre_ids associated with them.
The form data looks like:
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<div class="checkbox">
<label><input type="checkbox" name="Genres[]" value="2">Classical</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="Genres[]" value="3">Hiphop</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="Genres[]" value="4">Jazz</label>
</div>
<input type="submit" name="submit" class="btn btn-primary btn-lg active" id="grad" value="Login" />
</form>
So effectively, for the classical example, what I want to achieve is to look up and find all genre_id, see if the value 2 is in the list of genre_ids, if so change the markup to:
<label><input type="checkbox" name="Genres[]" value="2"<? php if(somecondition = 2) {echo "checked"} ?> >Classical</label>
However, I'm having a hard time putting this into code. Can you help me out?