Jump to content

dynamic select


proctk

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.