Here's a quick explanation:
My first while pulls four tv shows from the database. My second one finds if the current user has rated any of them. Funny thing is, if my second while loop doesn't find a score for one of the four tv shows pulled from the db, the unrated tv show doesn't display at all (so if the user gave a score to three of them, the fourth unrated one disappears.)... Why is that ?
Below I have a radio form where I want to precheck the score a user gave to the tv show (I would check if the score exists and add "checked" to the corresponding HTML line).
<?php
try {
$conn = new PDO('mysql:host=localhost;dbname=mytvbox', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM shows WHERE id > (SELECT MAX(id) - 4 FROM shows)');
$stmt->execute(array('id' => $id));
while($row = $stmt->fetch()) {
$show_id = $row[0];
$requete = "SELECT * FROM show_score WHERE show_id = $show_id AND user_id = $user_id";
$score = $conn->prepare($requete);
$score->execute(array('show_id' => $show_id));
while($row_score = $score->fetch()) {
var_dump($row_score);
?>
<div id="index-last-shows" class="three columns">
<div class="tip">
<a href="<?php echo $row[0]; ?>"><img src="<?php echo $row[4]; ?>" /></a>
</div>
<div class="tip-content">
<div class="tip-container">
<div class="tip-header">
<h1> <?php echo $row[1]; ?> </h1>
</div>
<div class="row">
<div class="twelve columns">
<div id="flash"></div>
<form id="<?php echo $row[0]; ?>">
<div class="your-score">
<div class="">Your Score</div> <div id="flash"></div>
<input class="hover-star" type="radio" name="tvshowrating" value="1" title="1"/>
<input class="hover-star" type="radio" name="tvshowrating" value="2" title="2"/>
<input class="hover-star" type="radio" name="tvshowrating" value="3" title="3"/>
<input class="hover-star" type="radio" name="tvshowrating" value="4" title="4"/>
<input class="hover-star" type="radio" name="tvshowrating" value="5" title="5"/>
<input class="hover-star" type="radio" name="tvshowrating" value="6" title="6"/>
<input class="hover-star" type="radio" name="tvshowrating" value="7" title="7"/>
<input class="hover-star" type="radio" name="tvshowrating" value="8" title="8"/>
<input class="hover-star" type="radio" name="tvshowrating" value="9" title="9"/>
<input class="hover-star" type="radio" name="tvshowrating" value="10" title="10"/>
<input type="hidden" id="show_id-<?php echo $row[0]; ?>" value="<?php echo $row[0]; ?>" />
<input type="hidden" id="user_id-<?php echo $row[0]; ?>" value="<?php echo $user_id ?>" />
<span id="hover-test" style="margin:0 0 0 20px;"></span>
<input id="submitscore" type="submit" value="Submit scores!" onclick="addScore(<?php echo $row[0]; ?>);" />
</div>
</form>
</div>
</div>
</div>
</div>
Edit: language a bit more clear.
Edit 2 : I'll put some screen shots of what's happening. If I put the closing brackets after the var_dump I get this: https://i.sstatic.net/frvV9.jpg, if I put them at the end like I need them to be I get this https://i.sstatic.net/34YDp.jpg
var_dump. Is there more code to this?