|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting a value from a drop down
Hello All!
From various posts on this forum I have managed to populate a drop down from a mysql database. I am now trying to pass the selected value using a hidden field in a form - this is when the weirdness begins. The only value I pass using a hidden field is the very last value in the drop down! Here is my code: echo "<form action='post_ad.php' method='POST'>\n"; echo "<select>"; echo "<option>Pick Ad Category"; while ($row = mysql_fetch_array($result)) { $categoryID =$row["categoryID"]; $category =$row["category"]; $options ="<option value=\"$categoryID\">$category</option>"; echo "$options"; } echo "</select>"; echo "<br />"; echo "<br />"; echo "<br />"; echo "<input type='hidden' name='location' value='$location'>"; echo "<input type='hidden' name='specificLocation' value='$specificLocation'>"; echo "<input type='hidden' name='category' value='$category'>"; echo "<input type='submit' value='submit'>"; echo "</form>\n"; Any help is appreciated. Thanks in advance. |
|
#2
|
||||
|
||||
|
What do you mean with " I am now trying to pass the selected value using a hidden field in a form"
passing a value through a hidden field is something else than pass it using a select. Simplest way to pass the selected value is by giving the <select> a name, so: <select name="thisname"> and then reading it in the next page from $_POST['thisname'] Hidden inputs have nothing to do with it. |
|
#3
|
|||
|
|||
|
ah! sorted! thanks a million : )
|
|
#4
|
||||
|
||||
|
you're welcome
|
|
#5
|
|||
|
|||
|
still having trouble passing from mysql populated drop down list
Quote:
Hi I am new to mysql/php. I think I can see why the last person was talking about hidden fields as I was thinking of trying that too. I am able to filter a database results page by simply typing the name into a text field. I am also able to populate a drop down list from mysql. However try as I might I cant combine this to filter database results from the drop down list. I had thought about populating a hidden field from the drop down and then that would pass the request to the display page. But I realise this isnt a good idea so please can you help me. Here is my code in the search page: <?php require_once('Connections/test.php'); ?> <?php mysql_select_db($database_test, $test); $query_myqry = "SELECT id, name FROM tblgroupinfo ORDER BY name "; $myqry = mysql_query($query_myqry, $test) or die(mysql_error()); $row_myqry = mysql_fetch_assoc($myqry); $totalRows_myqry = mysql_num_rows($myqry); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body><form action="results.php" method="get"> <select> <?php do { ?> <option value="<?php echo $row_myqry['id']?>" <?php if (!(strcmp($row_myqry['id'], $row_myqry['name']))) {echo "SELECTED";} ?>> <?php echo $row_myqry['name']?> </option> <?php } while ($row_myqry = mysql_fetch_assoc($myqry)); ?> <input name="button" type="submit"></select> </form> </body> </html> <?php mysql_free_result($myqry); ?> and here is my code from the results page: <?php require_once('Connections/test.php'); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $maxRows_query1 = 1; $pageNum_query1 = 0; if (isset($_GET['pageNum_query1'])) { $pageNum_query1 = $_GET['pageNum_query1']; } $startRow_query1 = $pageNum_query1 * $maxRows_query1; $colname_query1 = "1"; if (isset($_GET['name'])) { $colname_query1 = (get_magic_quotes_gpc()) ? $_GET['name'] : addslashes($_GET['name']); } mysql_select_db($database_test, $test); $query_query1 = sprintf("SELECT * FROM tblgroupinfo WHERE name = '%s'", $colname_query1); $query_limit_query1 = sprintf("%s LIMIT %d, %d", $query_query1, $startRow_query1, $maxRows_query1); $query1 = mysql_query($query_limit_query1, $test) or die(mysql_error()); $row_query1 = mysql_fetch_assoc($query1); if (isset($_GET['totalRows_query1'])) { $totalRows_query1 = $_GET['totalRows_query1']; } else { $all_query1 = mysql_query($query_query1); $totalRows_query1 = mysql_num_rows($all_query1); } $totalPages_query1 = ceil($totalRows_query1/$maxRows_query1)-1; $queryString_query1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_query1") == false && stristr($param, "totalRows_query1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_query1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_query1 = sprintf("&totalRows_query1=%d%s", $totalRows_query1, $queryString_query1); ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p><a href="group_dbase_interface.php">MENU</a></p> <table border="1"> <tr> <td>id</td> <td>name</td> <td>address1</td> <td>address2</td> <td>venue</td> <td>day</td> <td>contact_name</td> <td>contact_number</td> </tr> <?php do { ?> <tr> <td><?php echo $row_query1['id']; ?></td> <td><?php echo $row_query1['name']; ?></td> <td><?php echo $row_query1['address1']; ?></td> <td><?php echo $row_query1['address2']; ?></td> <td><?php echo $row_query1['venue']; ?></td> <td><?php echo $row_query1['day']; ?></td> <td><?php echo $row_query1['contact_name']; ?></td> <td><?php echo $row_query1['contact_number']; ?></td> </tr> <?php } while ($row_query1 = mysql_fetch_assoc($query1)); ?> </table> <p> </p> <p> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"> <?php if ($pageNum_query1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_query1=%d%s", $currentPage, 0, $queryString_query1); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"> <?php if ($pageNum_query1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_query1=%d%s", $currentPage, max(0, $pageNum_query1 - 1), $queryString_query1); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"> <?php if ($pageNum_query1 < $totalPages_query1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_query1=%d%s", $currentPage, min($totalPages_query1, $pageNum_query1 + 1), $queryString_query1); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"> <?php if ($pageNum_query1 < $totalPages_query1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_query1=%d%s", $currentPage, $totalPages_query1, $queryString_query1); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> </p> <p> Records <?php echo ($startRow_query1 + 1) ?> to <?php echo min($startRow_query1 + $maxRows_query1, $totalRows_query1) ?> of <?php echo $totalRows_query1 ?> </p> </body> </html> <?php mysql_free_result($query1); ?> I have used DWMX to set this up. I have called the select "name" which is the column name in my mysql db. I would really appreciate any help you can offer TIA Mim |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Getting a value from a drop down |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|