Page 1 of 1

PHP array to HTML combo box

Posted: Sat Nov 19, 2011 4:59 pm
by dcalladi
Hi, im resonably new to HTML and even more new to PHP i am taking some infomration from a database and putting it in an array in PHP
i then want to take that array and use it to fill in options for a combo box in HTML
i have this code os far

Code: Select all

<?php
            $sql="SELECT * FROM hotels order by city,name ;";
         
            $result_set = pg_Exec ($conn, $sql);
            $rows = pg_NumRows($result_set);

            if ((!$result_set) || ($rows < 1)) {
                  echo "<H1>ERROR - no rows returned</H1><P>";
                  exit;  //exit the script
                  }

            for ($j=0; $j < $rows; $j++)
               {
               $name = pg_result($result_set, $j, "name");
               $hotels[$j] = $name;
			   }
			   for ($i = 0; $i < $results = count($hotels); $i++){
			   }
?> 
and then this HTML
<div id="form">
<form>
Choose Your Journey <br />
From: <br />
<select name ="From">
<option value=></option>
<option value=></option>
<option value=></option>
<option value=></option>
</select>
<br />
To: <br />
<select name ="To">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>
</div>

i need both of those combox boxes to have the items from the array as options

Thank you very much in advance for your help.

Re: PHP array to HTML combo box

Posted: Sun Nov 20, 2011 6:11 am
by social_experiment
viewtopic.php?f=1&t=132938
This is a similar question (and answer) to what you want to do; only difference might be the type of database you are using but the principle stays the same.