Jump to content

Mysql populate


ngreenwood6

Recommended Posts

I am trying to get my database to populate a select option. I have the following code:

 

while($row = mysql_fetch_array($results)){

$dates = $row['dates'];

foreach($dates as $key => $values){
$key = $values;
echo "<form>";
echo "<select>";
echo "<option values='$values'>$values</option";
echo "</select>";
echo "</form>";
echo $values;
}
}

 

I know that this has to be wrong. Can someone please help me with the foreach and the database values.

Link to comment
https://forums.phpfreaks.com/topic/135400-mysql-populate/
Share on other sites

<?php
$output = "<form><select name=dates>";
while($row = mysql_fetch_array($results)){

$dates = $row['dates'];

foreach($dates as $key => $values){
// $key = $values; not sure what that is for 
$output .= "<option values='$values'>$values</option>";
//echo $values;
}
}
$output .= "</select></form>";

echo $output;
?>

 

Should work, assuming $dates is an array.

Link to comment
https://forums.phpfreaks.com/topic/135400-mysql-populate/#findComment-705242
Share on other sites

I have the select box but it is not populated with any data. I know that the data is in the database. Oh yean and I am still getting this error:

 

Warning: Invalid argument supplied for foreach() in C:\wamp\www\CMS\test.php on line 24

 

Line 24 is blank but line 25 is this:

foreach($dates as $key => $values){

Link to comment
https://forums.phpfreaks.com/topic/135400-mysql-populate/#findComment-705249
Share on other sites

<?php
$output = "<form><select name=dates>";
while($row = mysql_fetch_array($results)){
$output .= "<option values='" . $row['dates'] . "'>" . $row['dates'] . "</option>";
}
$output .= "</select></form>";

echo $output;
?>

 

Maybe that is what you are after?

Link to comment
https://forums.phpfreaks.com/topic/135400-mysql-populate/#findComment-705251
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.