cgray1223
asked on
use php to load html select options
Hello,
I have the below php and html code that works together to build a select control with it's options based on the results from a database query. The problem I'm facing is that I need to refresh this list without reloading the page. Currently the php script and the html code is all in one file. What I want to do is externalize the php script and perform a GET request from javascript to get the list again. How would I assign the options from the php script (via a GET request) for the select control?
The main reason for this is that within my application I'm removing some options based on some user actions. I have a need to refresh those options from a javascript function. Any other ideas?
I have the below php and html code that works together to build a select control with it's options based on the results from a database query. The problem I'm facing is that I need to refresh this list without reloading the page. Currently the php script and the html code is all in one file. What I want to do is externalize the php script and perform a GET request from javascript to get the list again. How would I assign the options from the php script (via a GET request) for the select control?
The main reason for this is that within my application I'm removing some options based on some user actions. I have a need to refresh those options from a javascript function. Any other ideas?
<?php
$con = mysql_connect('localhost', 'user', 'pwd');
$show_dialog='display:none;';
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db conn string", $con);
$sql="SELECT * FROM ALBUM_NEW";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["ID"];
$title=$row["TITLE"];
$options.="<OPTION VALUE=\"$id\">".$title;
}
mysql_close($con);
echo $options;
?>
<SELECT name="selectAlbum" id="selectAlbum">
<OPTION VALUE="0">-- Choose to Move --</option>
<?=$options?>
</SELECT>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
HTH
Ivo Stoykov
Open in new window