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? Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.