| | |
dynamic drop down menu in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 3
Reputation:
Solved Threads: 0
hi !
below is a simple html code which lets a user input a value and then passes it to a php program which runs a sql querry againt an oracle database displaying the result set.
what I would like to do is to be able to offer a drop down list of values to select from ( which will come from a table in oracle) instead of the user remembering n entering a value, how can i achieve that ?
thanks
Sami
--------------------------------------------- form2.html -----------------------------------------------------------------
---------------------------------------------- select2.php -----------------------------------------------------------
below is a simple html code which lets a user input a value and then passes it to a php program which runs a sql querry againt an oracle database displaying the result set.
what I would like to do is to be able to offer a drop down list of values to select from ( which will come from a table in oracle) instead of the user remembering n entering a value, how can i achieve that ?
thanks
Sami
--------------------------------------------- form2.html -----------------------------------------------------------------
html Syntax (Toggle Plain Text)
<form method="POST" action="select2.php"> <div align="left"><p><font face="BankGothic Md BT">host name?</font> <input type="text" name="host" size="14"><input type="submit" value="Submit"></p> </div></form>
---------------------------------------------- select2.php -----------------------------------------------------------
php Syntax (Toggle Plain Text)
<?php $host = $_POST["host"]; $hostname=strtoupper($host); $conn = oci_connect('SAMI', 'SAMI', 'emrep'); if (!$conn) { $e = oci_error(); print htmlentities($e['message']); exit; } $query = "SELECT * FROM INSTANCE where HOST_ID in (select HOST_ID from HOST_LOOKUP where HOST_NAME='$hostname')" ; $stid = oci_parse($conn, $query); if (!$stid) { $e = oci_error($conn); print htmlentities($e['message']); exit; } $r = oci_execute($stid, OCI_DEFAULT); if (!$r) { $e = oci_error($stid); echo htmlentities($e['message']); exit; } print '<table border="1">'; while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { print '<tr>'; foreach ($row as $item) { print '<td>'.($item?htmlentities($item):' ').'</td>'; } print '</tr>'; } print '</table>'; oci_close($conn); ?>
Last edited by peter_budo; Feb 4th, 2008 at 9:22 am. Reason: Inserting code tags
•
•
Join Date: Jan 2008
Posts: 57
Reputation:
Solved Threads: 5
•
•
•
•
what I would like to do is to be able to offer a drop down list of values to select from ( which will come from a table in oracle) instead of the user remembering n entering a value, how can i achieve that ?
PHP Syntax (Toggle Plain Text)
<select> <option value="value">Text</option> <option value="value">Text</option> </select>
So what you need to do is get the result set from your database, loop through the result set, and create an <option> tag for each item in the result set.
I'm not familiar with the Oracle functions, so you'll have to create the query and what not yourself, but here's the idea.
php Syntax (Toggle Plain Text)
$query = "SELECT value, text FROM table WHERE condition = TRUE"; $result = oci_execute($query, OCI_DEFAULT); echo '<select>'; while ($row = oci_fetch_array($result)) { echo '<option value='" . $row['value'] . '">' . $row['text'] . '</option>'; } echo '</select>';
Hopefully you get the concept out of that, and you can fill in the right query/oracle functions to get it to work.
The steps are basically...
- Write query
- Execute query
- Open the <select>
- Loop through query results
- Print an option for each value in the query result set
- Close the <select>
Good luck,
- Walkere
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Login page login help
- Next Thread: Help on Simple PHP Form
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





