#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Setting/Selecting from Dropdown in PHP -- pls help


    Hello ppl,

    I am a newbie to PHP and I am stuck at a point which may be simple for you experts. Thus, please give your advice on the following:

    Current Situation: The existing code of a web-page contains a dropdown with just one value in it. So when a user "presses" a submit button on this page, the ID of this single value in drop-down is saved in a variable and goes to another page.

    What I want to do: I want to add more value in this dropdown (from a DB query which I have). And after using this query I see the required 4 values in dropdown now. But what I need now is that:

    a. When I select any one value from the available 4 values, the respective ID should set in the variable which goes to another page. This is not happening.

    b. The default value in the drop down should be one which I want. And thus, if I don't change the default selected value, then this value's ID should be stored in the variable which goes to next page.

    Current Code (where some modification is to be done):
    Please read my two comments in the code to exactly know where I need help....thanks a lot!

    ---------------------xxxxxxxxxxxxxxxx------------------xxxxxxxxxxxxxxxxxx----------------------xxxxxxxxxxxxxxx------------------xxxxxxx---------------


    Case 24:

    $output[] = '<tr><td>Order Name</td><td>Shipping Status</td> <td>Billing Y/N</td><td>Billing Date</td><td>Delivered Date</td><td>Order ID * hidden</td><td>Note</td></tr>';
    while($row = oci_fetch_array($s,OCI_BOTH))
    {

    $output[] = '<tr><td><input type="text" name="txtOrderNm['.$j.']" class="widthed" value="'.$row["ORDER_NM"].'" readonly/></td>';

    $output[] = '<td><select class="widthed" name="txtShippingStatusIDsup['.$j.']" style="width:138px;">';
    if($row["REQUIRED_DT"]!=''){
    $query1 = "select SHIPPING_STATUS_ID, SHIPPING_STATUS_NAME FROM SHIPPING_STATUS where SHIPPING_STATUS_ID =25";
    }
    else{
    $query1 = "select SHIPPING_STATUS_ID, SHIPPING_STATUS_NAME FROM SHIPPING_STATUS where SHIPPING_STATUS_ID =24";
    }

    // currently only one value is coming in "SHIPPING_STATUS_ID" from the above query.

    $s1 = oci_parse($conn, $query1);
    oci_execute ($s1,OCI_DEFAULT);
    while($row1 = oci_fetch_array($s1,OCI_BOTH))
    {

    $output[] = '<option value = "';
    $output[] = $row1['SHIPPING_STATUS_ID'];
    $output[] = '" ';

    $output[] = '>';
    $output[] = $row1['SHIPPING_STATUS_NAME'];
    $output[] ='</option>';
    }
    $output[] = '</select></td>';


    $output[] = '<td><input type="text" name="txtBillingYn['.$j.']" class="widthed" value="'.$row["BILLING_STATUS_YN"].'" readonly style="width:85px;"/></td>';



    $output[] = '<td><input type="text" name="txtBillingDt['.$j.']" class="widthed" value="'.$row["BILLING_DT"].'" readonly style="width:100px;"/>';
    $output[] = '</td>';




    if($row["REQUIRED_DT"]!=''){
    $output[] = '<td><input type="text" name="txtDeliveredDt['.$j.']" class="widthed" value="'.$row["REQUIRED_DT"].'" style="width:194px;" />';
    $output[] = '<a href="#" onClick="setYears(1947, 2030); showCalender(this, \'txtDeliveredDt['.$j.']\');"><img src="./images/calender.png"></a>';
    $output[] = '</td>';
    $output[] = '<input type="hidden" name="txtShippingStatusID['.$j.']" value="24">';
    }
    else{
    $output[] = '<td><input type="text" name="txtDeliveredDt['.$j.']" class="widthed" value="'.$today.'" style="width:194px;" />';
    $output[] = '<a href="#" onClick="setYears(1947, 2030); showCalender(this, \'txtDeliveredDt['.$j.']\');"><img src="./images/calender.png"></a>';
    $output[] = '</td>';
    $output[] = '<input type="hidden" name="txtShippingStatusID['.$j.']" value="25">';
    }

    //comment

    //below

    // this value "txtShippingStatusID['.$j.']" is sent to another page. Since in this case, there is only one possible value for it, thus its hardcoded to '25'. But after I made my change, the value which gets stored in "txtShippingStatusID['.$j.']" should be of that row's ID which is selected in the dropdown. The modified query (original is above) is below:

    // select SHIPPING_STATUS_ID, SHIPPING_STATUS_NAME FROM SHIPPING_STATUS where SHIPPING_STATUS_ID in (23,24,25,26);

    //thus, the above code is to be changed such that "txtShippingStatusID['.$j.']" should store in it the value selected in drop-down.

    //comment

    //above


    $output[] = '<td><input type="text" name="txtOrderID['.$j.']
    " class="widthed" value="'.$row["ORDER_ID"].'" readonly style="width:150px;"/>';
    $output[] = '</td>';
    $output[] = '<td><input type="text" name="txtnote['.$j.']
    " class="widthed" value="'.$row["note"].'" />';
    $output[] = '</td>';
    echo "<hr>";
    }
    break;

    ---------------------xxxxxxxxxxxxxxxx------------------xxxxxxxxxxxxxxxxxx----------------------xxxxxxxxxxxxxxx------------------xxxxxxx---------------



    Any help appreciated....

    Thanks a zillion!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,392
    Rep Power
    594
    1) Please edit your post and use [ PHP ] tags for your code. See the sticky at the top of this forum.
    2) Although your code is very hard to read, unformatted, I don't see your <form> or <select> tags, only the <option> tag. The value of the selection, will show up in $_POST and I don't see where you use that either. It appears you only provided the code that partially creates your form.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,853
    Rep Power
    6351
    The new user guide is below this message.

    gw is right, your HTML is wrong.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo