/    Sign up×
Community /Pin to ProfileBookmark

combo box select problem

hi,

i am getting value of project from database

$query = “SELECT kunde,projektnr from emp_kunde”;
$result = mysql_query($query) or die(“Query failed: $query”);
$projekt = array();
while ($row = mysql_fetch_assoc($result))
{
array_push($projekt, $row[“projektnr”]);
}
$hprojekt = array_unique($projekt);

<td align=”center”>
<select name=”projekt”>
<? foreach($hprojekt as $value) { ?>
<option value=”<?= $value ?>”><?= $value ?></option>
<? } ?>
</select>
</td>
<?= $line[“projekt”] ?>//this is for printing

let say the value for project combo box is

Apple,Mango so when i select mango from project field and then submit the form i will get mango as printed value,i want mango must be shown selected in new line,whatever i select it will be shown as selectd on next new line,but in my case always Apple as selected in new line

let say in my list
1.Dad
2.Mom
3.Didi //if i select didi from this field then new line should be didi
4.Uncle as selected
5.Aunty

but above code always shown as Dad selected,

how i cna get selected item as shown in new line

thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pyroJul 18.2003 — Try changing this part of your code:

[code=php]<? foreach($hprojekt as $value) { ?>
<option value="<?= $value ?>"><?= $value ?></option>
<? } ?>[/code]


to this:

[code=php]<?PHP
foreach($hprojekt as $value) {
if ($value == "Uncle") { #set Uncle to the value that you want selected.
echo "<option value="$value" selected="selected">$value</option>";
}
else {
echo "<option value="$value">$value</option>";
}
}
?>[/code]
Copy linkTweet thisAlerts:
@zuzupusauthorJul 18.2003 — still its not working may be i put worng

if ($value == "Bosch EW") or if ($value == "<?= $value ?>")

which one is correct both not works

what value i have to put i dont want to hard code whatever the value selected it will be shown as selected on new line once form submits

thanks
Copy linkTweet thisAlerts:
@zuzupusauthorJul 21.2003 — <? foreach($hprojekt as $value) { ?>

<option value="<?= $value ?>" <? if ($HTTP_POST_VARS['projekt'] == $value){ echo "SELECTED";}?>><?= $value ?></option>

<? } ?>

project_00 //default selected value

project_01

project_02

project_03

when i choose project_02 and subit the form then im getting project_02 as selected

this works fine but when i login for next time im getting project_00 as default is it possible to get slected one as default one ,when login for next time

thanks in advance
×

Success!

Help @zuzupus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...