proctk Posted July 15, 2007 Share Posted July 15, 2007 Hi I'm trying to get the below code to populate a select option but I'm getting an error message. Warning: Invalid argument supplied for foreach() in /mnt/w0400/d11/s01/b02a5c57/www/familyclick.ca/photos/album.php on line 194 any ideas by. thank you <?php //Get & group photos $query_get_names = ("select * from image_files WHERE user_id = '$user_id' GROUP BY `album`"); $get_names = mysql_query($query_get_names)or die("SQL Error: $query_get_albums<br>" . mysql_error()); while($names=mysql_fetch_assoc($get_names)) { $files = $names['album']; echo $files; foreach ($files as $file) { echo "<option 'width:75px'"; if($value == $files) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/60067-dynamic-select/ Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 Because $names['album'] is not an array. Try... <?php $query_get_names = "select * from image_files WHERE user_id = '$user_id' GROUP BY `album`"; if ($result = mysql_query($query_get_names)) { if (mysql_num_rows($result)) { while($names = mysql_fetch_assoc($result)) { echo "<option 'width:75px' value='{$names['album']}'>{$names['album']}</option>\n"; } } } else { echo "SQL Error: $query_get_albums<br>" . mysql_error(); } ?> Link to comment https://forums.phpfreaks.com/topic/60067-dynamic-select/#findComment-298756 Share on other sites More sharing options...
proctk Posted July 15, 2007 Author Share Posted July 15, 2007 thank you that worked excellent. The next part to this I want the selection to auto select the value of album. which is found in the database. Link to comment https://forums.phpfreaks.com/topic/60067-dynamic-select/#findComment-298761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.