Jump to content

Paasing Variable from Drop Down Menu


brax23

Recommended Posts

I've researched but can't find anything that helps.  I'm using the fetch_array function to query a table then build a drop down menu from the results.  I have several drop down menus that I'm creating using the same fetch_array statement.  I'd like to be able to pass each chosen variable/value from each of the separate drop down menus to the next page.  Can someone suggest anything?  Here's the code:

$members_list = "<select name='name';'>";
$members_list .= "<option selected></option>";
$query_members = "SELECT ProjectNumber,ProjectName FROM projects ORDER BY ProjectNumber";
$result_members = mysql_query($query_members) or die("QUERY MEMBERS FAILED: ".mysql_error());
while ($line = mysql_fetch_array($result_members)) {
$itemnumber = $line['ProjectNumber'];
$description = $line['ProjectName'];
$members_list .= "<option value='$itemnumber'>$itemnumber $description</option>";
}

$members_list .= "</select>";




$codes_list = "<select name='code';'>";
$codes_list .= "<option selected></option>";
$query_codes = "SELECT WorkCode, Description FROM workcodes ORDER BY WorkCode";
$result_codes = mysql_query($query_codes) or die("QUERY MEMBERS FAILED: ".mysql_error());
while ($line = mysql_fetch_array($result_codes)) {
$codenumber = $line['WorkCode'];
        $codedescription = $line['Description'];
$codes_list .= "<option value='$codenumber'>$codenumber $codedescription</option>";
}

$codes_list .= "</select>";


echo "<form method='get' action='Time_3.php'>";
echo "<table border='0' width='50%' cellspacing='0' cellpadding='1'>";

echo "		<td><table border='0' width='100%' cellspacing='0'>";
echo "			<tr>";
echo "				<td width='5%'> </td>";

echo "			<tr>";
echo "				<td width='5%'> </td>";
echo "				<td width='95%'> </td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td colspan='1'><table border='0' width='40%'>";
echo "					<tr>";
echo "						<td>Project: </td>";
echo "                                          <td>Task Code: </td>";
echo "						<td>Time: </td>";
echo "						<td>Description: </td>";
echo " <tr></tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time1' size='2'> </td>";
echo "                                          <td><input type='text'name='description1' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time2' size='2'> </td>";
echo "                                          <td><input type='text' name='description2' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time3' size='2'> </td>";
echo "                                          <td> <input type='text' name='description3' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time4' size='2'> </td>";
echo "                                          <td> <input type='text' name='description4' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time5' size='2'> </td>";
echo "                                          <td> <input type='text' name='description5' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time6' size='2'> </td>";
echo "                                          <td> <input type='text' name='description6' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time7' size='2'> </td>";
echo "                                          <td> <input type='text' name='description7' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time8' size='2'> </td>";
echo "                                          <td> <input type='text' name='description8' size='140'></td>";
echo "				</table></td>";
echo "			</tr>";
echo "		</table></td>";
echo "	</tr>";
echo "</table>";



echo "<input type='submit' value='Submit' />";

echo "</form>";

Link to comment
Share on other sites

Thanks wildteen88.  You have helped me several times in these forums and I appreciate it.  I've tried the $_POST and $_GET form methods on the first page where the menu is created but for some reason either the value is not passing or I'm not asking for it correctly.  Here's the code on the next page where I'm simply trying to echo the value:

echo $_GET['$members']; echo $_GET[['$codes_list'];

Link to comment
Share on other sites

Thank you DarkWater.  I'm actually working in in html and php so my code is:

<?PHP
mysql_connect(host_name,user_name, pass_word) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);


$members_list = "<select name='name';'>";
$members_list .= "<option selected></option>";
$query_members = "SELECT ProjectNumber,ProjectName FROM projects ORDER BY ProjectNumber";
$result_members = mysql_query($query_members) or die("QUERY MEMBERS FAILED: ".mysql_error());
while ($line = mysql_fetch_array($result_members)) {
$itemnumber = $line['ProjectNumber'];
$description = $line['ProjectName'];
$members_list .= "<option value='$itemnumber'>$itemnumber $description</option>";
}

$members_list .= "</select>";




$codes_list = "<select name='code';'>";
$codes_list .= "<option selected></option>";
$query_codes = "SELECT WorkCode, Description FROM workcodes ORDER BY WorkCode";
$result_codes = mysql_query($query_codes) or die("QUERY MEMBERS FAILED: ".mysql_error());
while ($line = mysql_fetch_array($result_codes)) {
$codenumber = $line['WorkCode'];
        $codedescription = $line['Description'];
$codes_list .= "<option value='$codenumber'>$codenumber $codedescription</option>";
}

$codes_list .= "</select>";


echo "<form method='get' action='Time_3.php'>";
echo "<table border='0' width='50%' cellspacing='0' cellpadding='1'>";

echo "		<td><table border='0' width='100%' cellspacing='0'>";
echo "			<tr>";
echo "				<td width='5%'> </td>";

echo "			<tr>";
echo "				<td width='5%'> </td>";
echo "				<td width='95%'> </td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td colspan='1'><table border='0' width='40%'>";
echo "					<tr>";
echo "						<td>Project: </td>";
echo "                                          <td>Task Code: </td>";
echo "						<td>Time: </td>";
echo "						<td>Description: </td>";
echo " <tr></tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time1' size='2'> </td>";
echo "                                          <td><input type='text'name='description1' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time2' size='2'> </td>";
echo "                                          <td><input type='text' name='description2' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time3' size='2'> </td>";
echo "                                          <td> <input type='text' name='description3' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time4' size='2'> </td>";
echo "                                          <td> <input type='text' name='description4' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time5' size='2'> </td>";
echo "                                          <td> <input type='text' name='description5' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time6' size='2'> </td>";
echo "                                          <td> <input type='text' name='description6' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time7' size='2'> </td>";
echo "                                          <td> <input type='text' name='description7' size='140'></td>";

echo "					</tr>";
echo "						<td>$members_list</td>";
echo "						<td>$codes_list</td>";
echo "                                          <td><input type='text' name='time8' size='2'> </td>";
echo "                                          <td> <input type='text' name='description8' size='140'></td>";
echo "				</table></td>";
echo "			</tr>";
echo "		</table></td>";
echo "	</tr>";
echo "</table>";



echo "<input type='submit' value='Submit' />";

echo "</form>";

?>

  I still can't see where I've got any syntax errors on my second page trying to echo with $_GET['name'] or $_GET['code'].  Although I did have an error on last post [[ but corrected it.  Thanks for your help and patience with a beginner.

Link to comment
Share on other sites

Here's where you have syntax errors:

$members_list = "<select name='name';'>";

 

It should be:

$members_list = "<select name='name'>";

 

Notice the extra ;' in the original.  You did that in a few places I think.  That could possible cause some issues.  And $_GET['code'] and $_GET['name'] should work.

Link to comment
Share on other sites

Validate

 

Or, you can just go to the page you want to validate, then copy and paste this into the address bar and press Enter:

javascript:void(window.open('http://validator.w3.org/check?uri='+window.location.href,'','width=800,height=900,status=yes,resizable=yes,scrollbars=yes,location=yes'));

 

Link to comment
Share on other sites

Thanks very much DarkWater.  Looks like it's working.  It's only passing the values from the last menu/row but I think I can fix that by using multiple forms (one for each row of menu's) then name each menu differently.  Again, thanks for your help, you sure save people like me a lot of frustration and I appreciate it.

Link to comment
Share on other sites

Thanks very much DarkWater.  Looks like it's working.  It's only passing the values from the last menu/row but I think I can fix that by using multiple forms (one for each row of menu's) then name each menu differently.  Again, thanks for your help, you sure save people like me a lot of frustration and I appreciate it.

 

Or you can try out naming the element with an array name such as name='foo[]', then $_POST['foo'] will be a multi-dimensional array of everything selected.  And I'm glad to help. =)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.