troj71 Posted May 13, 2006 Share Posted May 13, 2006 I work in a hospital and I am using php, postgres and apache to replaceold paradox databases. I have made a form that contains a dropdownmenu of the hospital units so I can choose the group of patient basedon the unit they are on. For some reason my code has each unitappearing 2 times in the drop down so the dropdown looks like thisunit1unit1unit2unit2and so on. I have tested the query in the pgadim query window and Iget only one occurance. then I wrote the simple script:?php pg_connect("host=localhost dbname=liberty user=postgrespassword=password") or die; $qunit = pg_query("SELECT unitid, unitname FROM li_unit ORDER BYunitname"); while($myunits=pg_fetch_array($qunit)){ $eachid=$myunits["unitid"]; $eachunit=$myunits["unitname"]; echo "$eachid $eachunit<br>\n"; } ?>and I get the simple out put of1 unit12 unit23 unit34 unit4Yet the below code gives me the double occurance of each unit. here isthe code.<html><head><body> <form name="unitchoice" method="post" action="<?php print$_SERVER['PHP_SELF']?>"> <select name="homeunits"> <?php pg_connect("host=localhost dbname=liberty user=postgrespassword=password") or die; $qunit = pg_query("SELECT unitid, unitname FROM li_unit ORDER BYunitname"); while($myunits=pg_fetch_array($qunit)){ $eachid=$myunits["unitid"]; $eachunit=$myunits["unitname"]; ?> <option value=<?php echo $eachunit;?>><?php echo$eachunit;?></option> <?php } ?> </select> <input type="Submit" name="updateunit" value="Change Unit"> </form></body></head></html> Any suggestions? Link to comment https://forums.phpfreaks.com/topic/9578-getting-duplicate-entries-in-drop-down-list-populated-from-postgrsql-table/ Share on other sites More sharing options...
emehrkay Posted May 13, 2006 Share Posted May 13, 2006 try changing this[code] while($myunits=pg_fetch_array($qunit)){$eachid=$myunits["unitid"];$eachunit=$myunits["unitname"]; ?><option value=<?php echo $eachunit;?>><?php echo$eachunit;?></option><?php}[/code]to [code] while($myunits=pg_fetch_array($qunit)){$eachid=$myunits["unitid"];$eachunit=$myunits["unitname"]; echo "<option value=\"". $eachunit ."\">". $eachunit ."></option>\n"; \\ "\n" so the code looks clean when view souce}[/code] Link to comment https://forums.phpfreaks.com/topic/9578-getting-duplicate-entries-in-drop-down-list-populated-from-postgrsql-table/#findComment-35372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.