Results 1 to 4 of 4

Thread: combo box select problem

  1. #1
    Join Date
    Jun 2003

    combo box select problem


    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>
    <? } ?>
    <?= $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
    3.Didi //if i select didi from this field then new line should be didi
    4.Uncle as selected

    but above code always shown as Dad selected,

    how i cna get selected item as shown in new line

    arun krishnan

  2. #2
    Join Date
    Dec 2002
    High on life
    Try changing this part of your code:

    PHP Code:
    <? foreach($hprojekt as $value) { ?> 
    <option value="<?= $value ?>"><?= $value ?></option> 
    <? ?>
    to this:

    PHP Code:
    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 {
    "<option value=\"$value\">$value</option>";


    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    Jun 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

    Last edited by zuzupus; 07-18-2003 at 10:02 AM.

  4. #4
    Join Date
    Jun 2003

    Re: combo box select problem

    <? foreach($hprojekt as $value) { ?>
    <option value="<?= $value ?>" <? if ($HTTP_POST_VARS['projekt'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
    <? } ?>
    project_00 //default selected value

    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
    arun krishnan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles