Hi, I have a small problem in my code and I need your help. Well Im using fetch_assoc to get data from database and I need to get the ID number of each of returned values. the issue is that my code only return the ID number of the last data. Here's my code:
<form method="post" action="action.php">
<select name="album" style="border:1px solid #CCC; font-size:11px; padding:1px">
<?php
$sql = "SELECT * FROM table";
$stmt = $dbh -> prepare($sql);
$stmt -> execute();
while($row = $stmt -> fetch(PDO::FETCH_ASSOC))
{
$album_ID = $row['album_ID'];
$value = $row['album_name'];
print "<option value ='". $value ."'>". $value. "</option>";
}
?>
</select>
<input type="hidden" name="album_ID" value="<?php print $album_ID?>"/>
</form>
I would like the hidden input type holds the selected album id, but it always holds the album id of the last data. Please help.