I am trying to retrieve data from the jokecategory table and place it within checkboxes. This is the SQL statement that I am using:
$sql = "SELECT joke.id, joke.joke_text, joke.joke_date, author.name, author.email, jokecategory.category_id
FROM joke
INNER JOIN author ON joke.author_id = author.id
INNER JOIN jokecategory ON joke.id = jokecategory.joke_id
WHERE joke.id = :id";
$stmt = $dbConnection->prepare($sql);
$stmt->bindValue(':id', $id);
$stmt->execute();
$data = $stmt->fetch();
$joke_id = $data['id'];
$joke_text = $data['joke_text'];
$joke_date = $data['joke_date'];
$author_name = $data['name'];
$author_email = $data['email'];
This is what I have tried to retrieve the data:
<fieldset>
<legend class="control-label">Categories:</legend>
<?php foreach ($data['category_id'] as $checkbox) { ?>
<div class="controls">
<label for="category<?php echo($checkbox['id']);?>">
<input type="checkbox" name="categories[]" id="category<?php echo($checkbox['id']); ?>" value="<?php echo($checkbox['id']); ?>">
<?php echo($checkbox['name']); ?></label>
</div>
<?php } ?>
</fieldset>
Unsure of how to echo the category_id's back out from the jokecategory table and place within checkboxes. Could someone kindly provide some assistance?
Aucun commentaire:
Enregistrer un commentaire