navneesh Posted April 4, 2013 Share Posted April 4, 2013 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): ---------------------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! Quote Link to comment https://forums.phpfreaks.com/topic/276525-settingselecting-value-from-drop-down-in-php-please-help/ Share on other sites More sharing options...
computermax2328 Posted April 4, 2013 Share Posted April 4, 2013 (edited) Hey, Welcome to the club! I am surprised no one picked this one up yet. I haven't been able to look at your code yet, but to start I am going to put this in the forum in code tags so everyone can read it easier. There is a toggle on the text editor that looks like <>. That will put code tags around your code some it will make it look like this.... $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; I am going to take a look at this now and get back to you in a little bit... Is there more code to this?? It seems there are a few variables at the top that don't have any values. Edited April 4, 2013 by computermax2328 Quote Link to comment https://forums.phpfreaks.com/topic/276525-settingselecting-value-from-drop-down-in-php-please-help/#findComment-1422925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.