So I have a forum where a user has several characters they can post with. Now on the Edit post page I want to have the character that posted the post selected in the select menu. If the post have been sent and there was an error and the player choose to edit with a another character other than the one that originally made the post I want to have that character selected.
The problem is right now it prints the character that made the post as many times as the users number of characters.
So let's say the character that made this post is called Bob. And the user that owns Bob has 6 characters it will print Bob six times. When it should be Bob selected and then all the other characters. And if they chose to edit with another character I want to have that one selected and then print all the others. I hope you understand.
$post = $db->query("SELECT c.subject, a.message, a.hide_smilies, a.posted, b.name, b.user_id, c.id AS topic_id, c.closed, d.id AS forum_id, d.name AS forum_name FROM posts a
INNER JOIN characters b ON a.poster = b.id
INNER JOIN topics c ON a.topic_id = c.id
INNER JOIN forums d ON c.forum_id = d.id
WHERE a.id = $id")->fetch();
Character to edit with:
foreach($db->query("SELECT id, name FROM characters WHERE user_id = $is_logged_in ORDER BY name ASC") as $row):
if (isset($_POST['character']) && ($row['id'] == $_POST['character'])) {
echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
} else if (isset($post['name'])) {
echo '<option value="'.$row['id'].'" selected>'.$post['name'].'</option>';
} else {
echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
}
endforeach