rgb192
asked on
select menu inside/outside a function
code1:
when the select statement is outside the function
post works
code2:
when the select statement is inside the function
post does not work
-------------
both code1 and code2 show a drop down select menu
I am using php+sqlserver 2005
when the select statement is outside the function
post works
code2:
when the select statement is inside the function
post does not work
-------------
both code1 and code2 show a drop down select menu
I am using php+sqlserver 2005
<?php
//does not echo post
require_once('inc/common.php');
function displayProductFoldersC2($selected,$column) {
echo'<select name="$column">';
$sql = "SELECT distinct $column FROM rtrns where $column !='' ";
foreach(dbfetcharray($sql) as $p) {
if($p["$column"] == $selected) {
echo '<option SELECTED value="' . $p["$column"] .'">' . $p["$column"] . '</option>';
}
else {
echo '<option value="' . $p["$column"] .'">' . $p["$column"] . '</option>';
}
}
echo "</selected>";
}
$printable=$_POST[printable];
echo "<br>printable is $printable";
?>
<form action="#">
<?displayProductFoldersC2('Other','printable');?>
<input type=submit value=Submit>
</form>
<?php
//will echo post
require_once('inc/common.php');
function displayProductFoldersC2($selected,$column) {
//echo'<select name="$column">';
$sql = "SELECT distinct $column FROM rtrns where $column !='' ";
foreach(dbfetcharray($sql) as $p) {
if($p["$column"] == $selected) {
echo '<option SELECTED value="' . $p["$column"] .'">' . $p["$column"] . '</option>';
}
else {
echo '<option value="' . $p["$column"] .'">' . $p["$column"] . '</option>';
}
}
// echo "</selected>";
}
$printable=$_POST[printable];
echo "<br>printable is $printable";
?>
<form action="#">
<select name="printable">
<?displayProductFoldersC2('Other','printable');?>
</select>
<input type=submit value=Submit>
</form>
It's just a typo, you wrote </selected> instead of </select>. The output of the echo should be visible in the html source in both cases, it is just not rendered in the browser because the <select> is not closed.
Good point - I missed the typo. You'll need to do the quotes as well to get the correct name for the select field, though.
ASKER
still does not echo the post
that I select using select menu
that I select using select menu
<?php
//does not echo post
require_once('inc/common.php');
function displayProductFoldersC2($selected,$column) {
echo "<select name=\"$column\">";
$sql = "SELECT distinct $column FROM rtrns where $column !='' ";
foreach(dbfetcharray($sql) as $p) {
if($p["$column"] == $selected) {
echo '<option SELECTED value="' . $p["$column"] .'">' . $p["$column"] . '</option>';
}
else {
echo '<option value="' . $p["$column"] .'">' . $p["$column"] . '</option>';
}
}
echo "</select>";
}
$printable=$_POST[printable];
echo "<br>printable is $printable";
?>
<form action="#">
<?displayProductFoldersC2('Other','printable');?>
<input type=submit value=Submit>
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
echo'<select name="$column">';
Because you're using single quotes, it won't do variable substitution.
Try:
echo "<select name=\"$column\">";