Hello, I am using the tutorial from Oracle's site on how to connect to a database in PHP using code similar to the one shown below.


// Create connection to Oracle
$conn = oci_connect("phphol", "welcome", "//localhost/orcl");

$query = 'select * from departments';
$stid = oci_parse($conn, $query);
$r = oci_execute($stid);

// Fetch each row in an associative array
print '<table border="1">';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
   print '<tr>';
   foreach ($row as $item) {
       print '<td>'.($item !== null ? htmlentities($item, ENT_QUOTES) : '&nbsp').'</td>';
   print '</tr>';
print '</table>';


Lets say for example, once I have queried the data I need from the Oracle Database, how can I make it show up in an HTML option list similar to the one shown below?

  <label for="testOption"><b>Test Option</b><br/></label>
  <select name="testOption" id = "testOption">
    <option>Test Option</option>

Thank you in advance for your help.

4 Years
Discussion Span
Last Post by Navlag

?? just use the select instead of the table:

print '<label for="testOption"><b>Test Option</b><br/></label>
  <select name="testOption" id = "testOption">';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
   foreach ($row as $item) {
       print '<option>'.($item !== null ? htmlentities($item, ENT_QUOTES) : '&nbsp').'</option>'; // but you should include an id or something for the option value
print '</select>';

However, will that not just output an array ($item)? Should you be accessing it like this:





Diafol, thanks, that helped a lot.

I'm confused though. Does it matter if $item outputs an array? Why use $item['id']?

I'm not trying to step on your shoes, just geniunely curious, since $item seems to work just fine.

Thanks again, friend.


You can't echo an array as it will appear 'Array', but if you say it works, fine - not that I really understand why it should.


Strange. I'll try it both ways. Well, thank you again, diafol.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.