PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 12th, 2004, 05:24 PM
karlosp karlosp is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 karlosp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old August 12th, 2004, 06:27 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 996 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 11 m 36 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
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.

Reply With Quote
  #3  
Old August 12th, 2004, 07:25 PM
karlosp karlosp is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 karlosp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ah! sorted! thanks a million : )

Reply With Quote
  #4  
Old August 13th, 2004, 03:39 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 996 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2Folding Points: 883404 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 11 m 36 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
you're welcome

Reply With Quote
  #5  
Old August 24th, 2004, 01:06 PM
mim mim is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 mim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
still having trouble passing from mysql populated drop down list

Quote:
Originally Posted by Itsacon
you're welcome

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>&nbsp;</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>&nbsp; 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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Getting a value from a drop down


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT