| | |
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
Views: 4224 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





