I'm looking to add items from a array to a dropmenu, however I'm only able to add the last item in the array.
What I'm trying to do is:-
1st, Load and display data from one database field, and display it on a web page.
2nd Write the data to an array for later use.
I'm able to achieve the above ok.
3rd Further down my web page, run the array, and place the array contense into a drop menu, however I can only get it to display the last entry, instead of all of the array.
Code: Select all
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$results = $conn->query('SELECT * FROM central_site');
while ($row = $results->fetch()) {
print "<tr> <td width='5%'>";
echo $row['site_url'];
print "</td> <td width='5%'>";
echo $row['site_header'];
print "</td> <td width='5%' align='center'>";
echo $row['status'];
print "</td> <td width='5%' align='center'>";
//echo "<select name=$row['_id'] size='1'>";
echo "<select name='com_x' size='1'>";
echo "<option selected='selected'>Select</option>";
echo "<option>Edit</option>";
echo "<option>Pause</option>";
echo "<option>Delete</option>";
echo "</select>";
print "</td></tr>";
//$mysite[] = array($row['site_url']);
$mysite = array($row['site_url']); // Try this
//$mysite[] = $row['site_url'];
$domain_end++;
//$drows[] = $row['site_url'];
}
$conn = null; // Close Connection
}catch(PDOException $e ){ }
?>
Code: Select all
<select name="comdomain" size="1">
<option selected="selected">Select</option>
<?
$x=0;
// Working progress
for ($x = 0; $x <= $domain_end; $x++) {
echo "<option>" . $mysite[$x] . "</option>";
//print "<option>" . $x . "</option>";
//print "<option>" . $mysite[$x] . "<br></option>";
}
?>
</select>
Have I gone wrong, or how do I add the whole array to the drop menu please?
Thank You.