PHP - For Loop With Select Tag Always Selects Last Value Option
Hey guys there is probably a simple fix to this but i am just not seeing it ... Im createing a form that has error catching and self submitting valuse. I am trying to use a for loop to create all of the values and if the form is returned with an error then the correct values will still be filled out but i cant seem to get this loop to work. Every time i submit the form it doesnt matter what option i select it always comes back with the last one in the list or 30 in this case.
the problem code is below.. Any help would be appreciated. Code: [Select] <?php for($i=1; $i<=30; $i++){ echo'<option value="'.$i.'"'; if(isset($_POST['petsAge'])== $i){ echo ' selected="selected"';} echo '>'.$i.'</option>'; } ?> Similar TutorialsHi.. I need to save data from a while loop and data from select option, Now I encountered that using my query I only save is the last part of my while loop and also the data that I choose in select option did not save. here is my code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items = $_POST['Items']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty', UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy', ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'"; $result = mysql_query($sql, $con); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <style type="text/css"> #ddcolortabs{ margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs a span{ float:none; } #ddcolortabs a:hover{ background-color: #678b3f; } #ddcolortabs a:hover span{ background-color: #678b3f ; } #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style type="text/css"> #ddcolortabs1{ position: relative; top: 10px; margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs1 ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs1 li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs1 a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs1 a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs1 a span{ float:none; } #ddcolortabs1 a:hover{ background-color: #678b3f; } #ddcolortabs1 a:hover span{ background-color: #678b3f ; } #ddcolortabs1 #current a, #ddcolortabs1 #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style> #SR_date{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #SR_number{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 270px; width: auto; height: auto; float: left; top : 10px; } table { margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: .9em; border: 1px solid #DDD; width: auto; } th { font-family: Arial, Helvetica, sans-serif; font-size: .7em; background: #694; color: #FFF; padding: 2px 6px; border-collapse: separate; border: 1px solid #000; } td { font-family: Arial, Helvetica, sans-serif; font-size: .7em; border: 1px solid #DDD; text-align: left; } #RequestedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #ApprovedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #ReceivedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #IssuedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; margin-right: 120px; } #save_btn{ position: relative;; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; top: 10px; } </style> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items = document.getElementById("Items").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<tr> <td style='border: none;'> </td> <td style='border: none;'> <input type='text' name='SubItems' value='$row_sub[SubItems]' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode' value='$row_sub[ItemCode]' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM' value='$row_sub[UoM]' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class' value='$row_sub[Class]' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description' value='$row_sub[Description]' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation' value='$row_sub[BINLocation]' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } } ?> </table> </div> <div id='RequestedBy'> <label>Requested By:</label> <select name="Requested_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ApprovedBy'> <label>Approved By:</label> <select name="Approved_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ReceivedBy'> <label>Received By:</label> <select name="Received_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id='IssuedBy'> <label>Issued By:</label> <select name="Issued BY"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onclick="save_sr()"> </div> </body> </html> I also I attach the display data. Thank you Hello,
Any ideas why server resources not exhausted on the code below, when my.cnf and php.ini are both set to use half the resources each? PHP & MySQL will both utilize all allotted resources on other scripts, so it's not a tuning problem. There is no script-side tuning.
The bottleneck: pdo select as shown below
foreach($bigList as $listObject) { $sql = $dbl->prepare("SELECT * FROM fewMillionRows WHERE indexedCol1=:indexedCol1 AND indexedCol2=:indexedCol2 AND indexedCol3=:indexedCol3 AND indexedCol4=:indexedCol4 LIMIT 1"); $sql->execute($preparedValues); $return = $sql->fetchAll(PDO::FETCH_ASSOC); }On a dedicated server with 8GB RAM, the server uses >5% cpu/ram but takes a long time to finish the script. Second Question What are some alternative designs? Because the column values all happen to be alphanumeric, I could select the entire table and store it in an array. Accessing the keys like so: indexedCol1indexedCol2indexedCol3indexedCol4. Results: MyISAM - Select Whole Table: 30 seconds MyISAM – Select Individual Rows (10k times) – 68 seconds InnoDB – Select Whole Table: 30 seconds InnoDB – Select Individual Rows (10k times) – 131 seconds I am surprised it takes so long to select a whole table. The server resources use 1% for about 20 seconds, then cpu/ram jump to 30%+ for about 10 seconds. This is still drastically faster than individual selects. In this instance, $bigList is over 500k items. At 68 seconds per 10k rows it’s absurdly long. Building an array with key/values is the only realistic way I currently know of, but I suspect there is a much better way of doing this. As far as I know, I cannot do a select like so: SELECT * FROM t1 WHERE (column1,column2,column3) IN ((val1, val2,val3), (val4, val5,val6)) There is no way to determine whether a row was found for each entry as far as I know. ok so below is the select option for my form i creatig should this select have the name 0f bday form of the three selects so that when i put it into a variable it could just be $birthday = $_POST = ['bday']; Code: [Select] <select class="drop" name="bday"> <option>Month</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select class="drop" name="bday"> <option>Day</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select class="drop" name="bday"> <option>Year</option> <option value="2011">2011</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> <option value="1900">1900</option> </select> I am adding to a shopping cart using sessions, when I add a product with a selected size it echoes the correct size as text but when applying it to my option boxes as selected, it just shows the last item in the select box. here is the code for the session variables <?php for ($basket_counter=0;$basket_counter<$_SESSION['ses_basket_items'];$basket_counter++) { $price=sprintf("%01.2f",$ses_basket_price[$basket_counter]); $quantity=$ses_basket_amount[$basket_counter]; $code=$ses_basket_stockcode[$basket_counter]; $itemID=$ses_basket_id[$basket_counter]; $name=$ses_basket_name[$basket_counter]; $image=$ses_basket_image[$basket_counter]; $size=$ses_basket_size[$basket_counter]; $sizechoice=$ses_basket_sizechoice[$basket_counter]; // create array from sizes and make the option box selections if ($sizechoice!="" && (!in_array($sizechoice, array('One Size', 'one size', 'free size', 'Free Size', 'Adjustable', 'adjustable')))) { // add size trigger $sizelist="add"; //create the array $sizepick=explode(",", $sizechoice); } else { $sizepick=$sizechoice; } // adjust gst for AU customers if ($country='AU') { $price=sprintf("%01.2f",($price*1.1)); $unit=sprintf("%01.2f",($price/$quantity)); } else { $unit=sprintf("%01.2f",($price/$quantity)); } ?> and this bit inside the same loop displayes the select box for size <?php if ($sizelist && $sizelist='add') { echo "<select name='size' id='size' style='vertical-align:middle;'>"; foreach($sizepick AS $sizes) { if ($sizes==$size) { echo "<option value='$size' selected='selected'>$size</option>"; } else { echo "<option value='$sizes'>$sizes</option>"; }} echo "</select>"; } else { echo $size; } ?> appreciate any help on this Hi.. I need to add code to check if the compound that was choose is reach the maximum value then if it is already reach theirs a notification displayed that he already gain the maximum. the problem is..I don't know how can I check if what the user choose before run the condition. here is my code: Code: [Select] <?php $config['BASE_DIR'] = dirname(dirname(__FILE__)); $config['BASE_DIR'] = $config['BASE_DIR']. '\MES PROJECT'; define('SMARTY_DIR', $config['BASE_DIR']. '/INCLUDE/smarty/libs/'); require(SMARTY_DIR . 'Smarty.class.php'); $smarty = new Smarty(); $smarty = new Smarty(); $smarty->template_dir = $config['BASE_DIR']. '/smarty/templates'; $smarty->config_dir = $config['BASE_DIR']. '/smarty/config'; $smarty->cache_dir = $config['BASE_DIR']. '/INCLUDE/smarty/cache'; $smarty->compile_dir = $config['BASE_DIR']. '/INCLUDE/smarty/templates_c'; // ================================================================================================================= $con= mysql_connect('localhost', 'root', ''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $hostAddr = $_SERVER['REMOTE_ADDR']; $terminal = $hostAddr; //<-enable this in server //$terminal = $_POST['doThis']; //<- disable this in server $terminal = "192.168.1.101"; switch ($terminal) { case "192.168.1.101" : //<< enable this in server //case "1" : $smarty->assign('process', 'Rubber/Chemical Preparation'); $smarty->assign('termNo', 'Terminal 1'); $smarty->assign('text_name1','Compound Code'); $smarty->assign('text_name2','Lot Traveler ID'); $smarty->assign('text_name3','Kit Weight '); $smarty->assign('text_name4','Operator Code'); [b] $smarty->assign('compoundIndexValue', array('0', 'P28', 'P30', 'P32', 'P33', 'P35', 'P35M', 'P38', 'P40', 'P41', 'P42', 'P43', 'P46', 'P47', 'PXX', 'P35W'));[/b] $smarty->assign('names', array('<Choose Code>', 'P28', 'P30', 'P32', 'P33', 'P35', 'P35M', 'P38', 'P40', 'P41', 'P42', 'P43', 'P46', 'P47', 'PXX', 'P35W')); $smarty->assign('weightIndexValue', array('0', '60.145', '68.980', '65.381', '69.270', '49.360', '68.610', '54.880', '73.300', '51.973', '52.944', '57.627', '45.997', '69.196', '70.000', '55.000')); $smarty->assign('kitWeight', array('<Choose Weight>','60.145', '68.980', '65.381', '69.270', '49.360', '68.610', '54.880', '73.300', '51.973', '52.944', '57.627', '45.997', '69.196', '70.000', '55.000')); //Chemical weighing Process : Terminal 1 $smarty->display('header.tpl'); // common Header $smarty->display('box_1.tpl'); $smarty->display('footer.tpl'); [b] $compound = mysql_real_escape_string($_POST['compoundIndexValue']); $sql = "SELECT P28, P28_max, P28_min, P30, P30_max, P30_min, P32, P32_max, P32_min, P33, P33_max, P33_min, P35, P35_max, P35_min, P35M, P35M_max, P35M_min, P35W, P35W_max, P35W_min, P38, P38_max, P38_min, P41, P41_max, P41_min, P42, P42_max, P42_min, P43, P43_max, P43_min, P46, P46_max, P46_min, P47, P47_max, P47_min FROM parameter_settings"; $res_pcode = mysql_query($sql, $con); $row = mysql_fetch_assoc($res_pcode); $P28 = $row['P28']; $P28_max = $row['P28_max']; $P28_min = $row['P28_min']; $P30 = $row['P30']; $P30_max = $row['P30_max']; $P30_min = $row['P30_min']; $P32 = $row['P32']; $P32_max = $row['P32_max']; $P32_min = $row['P32_min']; $P33 = $row['P33']; $P33_max = $row['P33_max']; $P33_min = $row['P33_min']; $P35 = $row['P35']; $P35_max = $row['P35_max']; $P35_min = $row['P35_min']; $P35M = $row['P35M']; $P35M_max = $row['P35M_max']; $P35M_min = $row['P35M_min']; $P35W = $row['P35W']; $P35W_max = $row['P35W_max']; $P35W_min = $row['P35W_min']; $P38 = $row['P38']; $P38_max = $row['P38_max']; $P38_min = $row['P38_min']; $P41 = $row['P41']; $P41_max = $row['P41_max']; $P41_min = $row['P41_min']; $P42 = $row['P42']; $P42_max = $row['P42_max']; $P42_min = $row['P42_min']; $P43 = $row['P43']; $P43_max = $row['P43_max']; $P43_min = $row['P43_min']; $P46 = $row['P46']; $P46_max = $row['P46_max']; $P46_min = $row['P46_min']; $P47 = $row['P47']; $P47_max = $row['P47_max']; $P47_min = $row['P47_min']; $sql = "SELECT PCODE, total FROM kanban_checker WHERE PCODE = '$compound' ORDER BY PCODE"; $res_kanban = mysql_query($sql, $con); $row_kanban = mysql_fetch_assoc($res_kanban); $PCODE = $row_kanban['PCODE']; $total = $row_kanban['total']; if($compound == $P28 && $total == $P28_max){ echo "<script type='text/javascript'>notify(P28 gain total maximum)</script>"; } else { echo ''; } if($compound == $P30 && $total == $P30_max){ echo "<script type='text/javascript'>notify(P30 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P32 && $total == $P32_max){ echo "<script type='text/javascript'>notify(P32 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P33 && $total == $P33_max){ echo "<script type='text/javascript'>notify(P33 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P35 && $total == $P35_max){ echo "<script type='text/javascript'>notify(P35 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P35M && $total == $P35M_max){ echo "<script type='text/javascript'>notify(P35M gain total maximum)</script>"; } else{ echo ''; } if($compound == $P35W && $total == $P35W_max){ echo "<script type='text/javascript'>notify(P35W gain total maximum)</script>"; } else{ echo ''; } if($compound == $P38 && $total == $P38_max){ echo "<script type='text/javascript'>notify(P38 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P41 && $total == $P41_max){ echo "<script type='text/javascript'>notify(P41 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P42 && $total == $P42_max){ echo "<script type='text/javascript'>notify(P42 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P43 && $total == $P43_max){ echo "<script type='text/javascript'>notify(P43 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P46 && $total == $P46_max){ echo "<script type='text/javascript'>notify(P46 gain total maximum)</script>"; } else{ echo ''; } if($compound == $P47 && $total == $P47_max){ echo "<script type='text/javascript'>notify(P47 gain total maximum)</script>"; } else{ echo ''; }[/b] break; case "192.168.1.102" : //<< enable this in server //case "2" : $smarty->assign('process', 'Compounding Process'); $smarty->assign('termNo', 'Terminal 2'); $smarty->assign('text_name1','Lot Traveler ID'); $smarty->assign('text_name2','Kit Weight'); $smarty->assign('text_name3','Machine Code'); $smarty->assign('text_name4','Operator Code'); $smarty->assign('machineID', array('0', 'B1', 'B2', 'B3', 'K1', 'K2', 'OM1', 'OM2', 'OM3', 'OM4', 'OM5', 'OM6', 'OM7')); $smarty->assign('machineIDdisplay', array('<Choose Machine ID>', 'B1', 'B2', 'B3', 'K1', 'K2', 'OM1', 'OM2', 'OM3', 'OM4', 'OM5', 'OM6', 'OM7')); $smarty->display('header.tpl'); // common Header $smarty->display('box_2.tpl'); $smarty->display('footer.tpl'); break; case "192.168.1.103" : //<< enable this in server //case "3" : $smarty->assign('process', 'Extrusion Process'); $smarty->assign('termNo', 'Terminal 3'); $smarty->assign('text_name1','Lot Traveler ID'); $smarty->assign('text_name2','Kit Weight'); $smarty->assign('text_name3','Machine Code'); $smarty->assign('text_name4','Operator Code'); $smarty->assign('machineID', array('0', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6')); $smarty->assign('machineIDdisplay', array('<Choose Machine ID>', 'E1', 'E2', 'E3', 'E4', 'E5', 'E6')); $smarty->display('header.tpl'); // common Header $smarty->display('box_2.tpl'); $smarty->display('footer.tpl'); break; case "192.168.1.104" : //<< enable this in server //case "4" : $smarty->assign('process', 'Half Shell Forming'); $smarty->assign('termNo', 'Terminal 4'); $smarty->assign('text_name1','Lot Traveler ID'); $smarty->assign('text_nameDG','New Lot ID'); $smarty->assign('text_name2','Machine ID'); $smarty->assign('text_name3','Output Qty.'); $smarty->assign('text_name4','Reject Qty.'); $smarty->assign('text_name5','Operator Code'); $smarty->assign('id', array('0', 'NTG1', 'NTG2', 'NTG3', 'NTG4', 'GTG1', 'SQG1', 'PL1')); $smarty->assign('id_name', array('<Choose Machine ID>', 'NTG1', 'NTG2', 'NTG3', 'NTG4', 'GTG1', 'SQG1', 'PL1')); $smarty->display('header.tpl'); // common Header $smarty->display('box_3.tpl'); $smarty->display('footer.tpl'); break; case "192.168.1.105" : //<< enable this in server //case "5" : $smarty->assign('process', 'Half Shell Deflashing'); //= to be implemented $smarty->assign('termNo', 'Terminal 5'); $smarty->assign('text_name1','Lot Traveler ID'); $smarty->assign('text_name2','Machine ID'); $smarty->assign('text_name3','Output Qty.'); $smarty->assign('text_name4','Reject Qty.'); $smarty->assign('text_name5','Operator Code'); $smarty->assign('id', array('0', 'US DEF.1', 'US DEF.2', 'FRENCH DEF.1', 'FRENCH DEF.2', 'THAILAND DEF.1', 'THAILAND DEF.2', 'HANAU 45 DEF.')); $smarty->assign('id_name', array('<Choose Machine ID>', 'US DEF.1', 'US DEF.2', 'FRENCH DEF.1', 'FRENCH DEF.2', 'THAILAND DEF.1', 'THAILAND DEF.2', 'HANAU 45 DEF.')); $smarty->display('header.tpl'); // common Header $smarty->display('box_3.tpl'); $smarty->display('footer.tpl'); break; } ?> My only purpose is to avoid adding data so i need to prompt if he already reach the maximum per compound. Thank you so much Hello, guys! Just a small first ever thread, where I ask a question where I hope anyone is able to help me out I am working on a project with a friend of mine for a company. I have a problem with the function on a form. I wonder; How do i change the option value of a form? Let's say if I choose a category like "Cake", I want the second drop down box to display different brands of cake. But if I choose bicycle for example, I want the option values to be different brands of bicycles. I hope you guys understand what I was trying to say here. Anyways, here is a sample image where I want this function to occur: Sample: Cheers and thanks in advance, Marius i have this select box in a form Code: [Select] <select name='theoptions' style='color: #000000;text-align:center;background-color:#DEDEDE;border: 1px solid #D99C29;width:163px;padding:5px;' onchange='optionChanged(this);ChgBox(this.value);'> <option value='1' >Your comment on</option> <option value='3' >Your question on</option> <option value='4' >Your expertise on</option> <option value='2' >Your image about</option> <option value='5' >Your website about</option> <option value='0' >Comparison</option> </select> on the page where the form directs to i have Code: [Select] $options = $_POST['theoptions']; I want to get option 5 specificially, how do i do that? I've been using an option that's a state, an example would be South Carolina or North Dekota. In the url the $_GET var turns it into South+Carolina or North+Dekota. Is this common and okay across different Browsers? I've tried ie and firefox and the + sign is addded but I was wondering if they're just designed to be as idiot proof as possible. Thanks I'm trying to pass php select option value to another page through url.but it's not working.please help me.
member.php
<?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("nordfxlk_member")or die(mysql_error()); $result = mysql_query("SELECT id,ugroup FROM ugroups"); ?> <select name='group' id='group' > <?php while ($line = mysql_fetch_array($result)) { echo '<option value=' . $line['ugroup'] . '>' . $line['ugroup'] . '</option>'; }?> </select> <a href="db_sql/add_group.php?ugroup=<?php echo $line['ugroup'] ;?>"> click</a>add_group.php include('../limoconfig.php'); if(!isset($_SESSION['adminuserid']) ) { header('Location:../index.php'); } else { $ugroup = $_GET['ugroup']; /*$id = $_GET['id'];*/ $acc_status = "update users set ugroup='".$ugroup."' where id=1931"; echo $acc_status; $rate = db::getInstance()->exec($acc_status); header('Location:../test.php'); } } OK so I'm having a pull my hair out moment. I have spent all day trying to figure this out. I have a select box for a list of customers where one customer is unique and I want that account to appear twice in the list. That part was easy and when selected the appropriate info populates the page. The problem I am having is that no matter which one of those two options I click it only selects the second option . So in other words if these are the two options in the list: Some Business Week 1 Some Business Week 2 when I click either, Some Business Week 2 is always the one selected even though the page populates correctly. Any thoughts on what I need to change? Code: [Select] <?php do { mysql_select_db($database_customers, $customers); $query_multiple = "SELECT accnt, week, alt FROM schedule WHERE accnt = " . $customer['accnt']; $multiple_sel = mysql_query($query_multiple, $customers) or die(mysql_error()); $multiple = mysql_fetch_assoc($multiple_sel); $multiple_run = $multiple['alt']; if($multiple_run > 1) { for ($i = 1; $i <= $multiple_run; $i++) { mysql_select_db($database_customers, $customers); $query_get_week = "SELECT week, alt FROM schedule WHERE accnt = " . $customer['accnt'] . " AND alt = " . $i; $get_week_sel = mysql_query($query_get_week, $customers) or die(mysql_error()); $get_week = mysql_fetch_assoc($get_week_sel); $version1 = $inv_title . " Week " . $get_week['week']; $version2 = $customer['name'] . " Week " . $get_week['week']; ?> <option value="report.php?accnt=<?php echo $customer['accnt']; ?>&alt=<?php echo $get_week['alt'];?>"<?php if (!(strcmp($version1, $version2))) {echo "selected=\"selected\"";} ?>><?php echo $version2; ?></option> <?php } } else { $version1 = $inv_title; $version2 = $customer['name']; ?> <option value="report.php?accnt=<?php echo $customer['accnt']; ?>&alt=<?php echo $multiple['alt'];?>"<?php if (!(strcmp($version1, $version2))) {echo "selected=\"selected\"";} ?>><?php echo $version2; ?></option> <?php } ?> <?php } while ($customer = mysql_fetch_assoc($customer_sel)); ?> If I have a variable and a hard coded select dropdown, what is the easiest way to compare the variable with the value and set that particular option's selected attributed to selected? Hi.. I got problem in logic on my problem in select option. Here is my scenario. I have select option which has a compound list: example: P28 P30 P32 P33 P35 and I have tables which has a total count of compound that was already transact. for example I already transact 10 P28 compound. it will save in kanban_checker table field Total. and I have parameter_settings table which has the maximum and minimum per compound: fields----------data P28------------P28 P28_max-----10 P28_min------6 P30------------P28 P30_max-----10 P30_min------6 P32------------P28 P32_max-----10 P32_min------6 P33------------P28 P33_max-----10 P33_min------6 now the logic is: if P28 total = P28_max then notify that he already reach the maximum..it will not produce P28 because he already reach the maximum. if P28 total = P28_min then produce P28. same with other compound. Now, I got a problem in coding and logic, because in the select option I'm not the one who code it.. I just one who need to add the additional function.. here is the code for select option and the function that was created by other, Code: [Select] $smarty->assign('text_name1','Compound Code'); $smarty->assign('compoundIndexValue', array('0', 'P28', 'P30', 'P32', 'P33', 'P35', 'P35M', 'P38', 'P40', 'P41', 'P42', 'P43', 'P46', 'P47', 'PXX', 'P35W')); <tr> <td class="tdMainText">{$text_name1}</td> <td> <select class="tdMainElement" id="selCompound" onchange="isSelected('selCompound','txtLotCode')" onclick="clearNotify()" onblur="this.focus();" onkeypress="return false">{html_options values=$compoundIndexValue output=$names selected="0"} </select> </td> </tr> <script type="text/javascript"> function isSelected(obj1, obj2) { if (!document.getElementById(obj1).disabled) { document.getElementById(obj1).disabled = true; } if (document.getElementById('clear').disabled) { document.getElementById('clear').disabled = false; //enable it } if ((document.getElementById('chkDownGrade') != null)) { if (!document.getElementById('chkDownGrade').disabled) { document.getElementById('chkDownGrade').disabled = true; } } if (document.getElementById(obj2).disabled) { document.getElementById(obj2).disabled = false; } document.getElementById(obj2).focus(); document.getElementById(obj2).focus(); //notify("Gain Maximum Total"); } function disable() { if (!document.getElementById('clear').disabled) { document.getElementById('clear').disabled = true; } else { document.getElementById('clear').disabled = false; } } function clearNotify() { if (document.getElementById('notice') != null) { document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box } } </script> and here is the code that I tried to add: Code: [Select] $compound = mysql_real_escape_string($_POST['compound']); $sql = "SELECT P28, P28_max, P28_min, P30, P30_max, P30_min, P32, P32_max, P32_min, P33, P33_max, P33_min, P35, P35_max, P35_min, P35M, P35M_max, P35M_min, P35W, P35W_max, P35W_min, P38, P38_max, P38_min, P41, P41_max, P41_min, P42, P42_max, P42_min, P43, P43_max, P43_min, P46, P46_max, P46_min FROM parameter_settings"; $res_pcode = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_pcode)){ $P28 = $row['P28']; $P28_max = $row['P28_max']; $P28_min = $row['P28_min']; $P30 = $row['P30']; $P30_max = $row['P30_max']; $P30_min = $row['P30_min']; $P32 = $row['P32']; $P32_max = $row['P32_max']; $P32_min = $row['P32_min']; $P33 = $row['P33']; $P33_max = $row['P33_max']; $P33_min = $row['P33_min']; $P35 = $row['P35']; $P35_max = $row['P35_max']; $P35_min = $row['P35_min']; $P35M = $row['P35M']; $P35M_max = $row['P35M_max']; $P35M_min = $row['P35M_min']; $P35W = $row['P35W']; $P35W_max = $row['P35W_max']; $P35W_min = $row['P35W_min']; $P38 = $row['P38']; $P38_max = $row['P38_max']; $P38_min = $row['P38_min']; $P41 = $row['P41']; $P41_max = $row['P41_max']; $P41_min = $row['P41_min']; $P42 = $row['P42']; $P42_max = $row['P42_max']; $P42_min = $row['P42_min']; $P43 = $row['P43']; $P43_max = $row['P43_max']; $P43_min = $row['P43_min']; $P46 = $row['P46']; $P46_max = $row['P46_max']; $P46_min = $row['P46_min']; $P47 = $row['P47']; $P47_max = $row['P47_max']; $P47_min = $row['P47_min']; } // $sub_lotcode = substr($lotCode, 9, 4); $sql = "SELECT PCODE, total FROM kanba_checker WHERE PCODE = '$sub_lotcode' ORDER BY PCODE"; $res_kanban = mysql_query($sql, $con); $row_kanban = mysql_fetch_assoc($res_kanban); $PCODE = $row_kanban['PCODE']; $total = $row_kanban['total']; if($compound = $P28 || $total == $P28_max){ echo "<script type='text/javascript'>alert(P28 gain total maximum)</script>"; } else{ } but I don't know if my code and my logic is correct. I think I did to add function. But I don't know how.. I hope someone can help me or guide me to solve my problem. Thank you so much.. HI All,
I am creating a dropdown box on an edit user form. The box is populated from a table ssm_role and relates to the user which is another table. I am wanting the value of the dropdown to be set as whatever the loaded user has in their database table. See the images below. $sql = "SELECT * FROM ssm_role ORDER BY role_name ASC"; if($result = mysqli_query($conn, $sql)){ if (mysqli_num_rows($result)>0){ while ($row = mysqli_fetch_array($result)){ echo "<option value='".$row['role_id']."'>".$row['role_name']."</option>"; } } } This is what i am currently doing to make the dropdown but obviously this isnt even attempting to set the default. Your help is always appreciated
What I'm wanting to do is pass the $propertyid = "1"; threw my select value as you can see. so it passes variable so to speak.' Code: [Select] print "<td>Control:<form action=\"dashboard.php\" method=\"GET\" target=\"_self\"> <select name=\"control\" onChange=\"this.form.submit()\"> <option selected></option> <option>Take a Payment</option> <option>Print Ledger </option> <option>-----------------</option> <option value=\"comadd?propid=$propertyid\">Add Communication</option> <option>----------------</option> <option>Modify Property</option> <option>Remote Property</option> </select></td>"; Hi, I am doing an EDIT user page and would like to check records with a dropdown and then set as selected, please help! <select name="BrokerID" class="small-input"> <option value="Please select an option">Please select a Broker</option> <?php while($row2 = mysql_fetch_array($broker)) { echo '<option name="BrokerID" value="'.$row2['BrokerID'].'">'.$row2['BrokerName'].'</option>'; } ?> </select> Hi, I am trying to create a drop down menu that will select a value that is stored in the database - right now the code creats a dropdown (with nothing selected) - hope someone can help. in the database, the values are stored as --null- Option1 Option2 Option3 my code is Code: [Select] $instruction = $_GET['instruction']; <?php <select id="instruction" name="instruction"> <option value="" <?php if (!empty($instruction) && $instruction == '' ) echo 'selected = "selected"'; ?>></option> <option value="Option1" <?php if (!empty($instruction) && $instruction == 'Option1') echo 'selected = "selected"'; ?>>Option1</option> <option value="Option2" <?php if (!empty($instruction) && $instruction == 'Option2') echo 'selected = "selected"'; ?>>Option2</option> <option value="Option3" <?php if (!empty($instruction) && $instruction == 'Option3') echo 'selected = "selected"'; ?>>Option3</option> </select> <? This is more of a Paypal question, but I'm using php on the listener and hopefully someone has run into this problem. I'm having trouble finding the correct POST name to use to get the OPTION SELECT for the item on my listener page. I tried: $option = $_POST['os0']; But, I'm not getting anything using that. I've also tried os0_x, on0, and on0_x. This is what I'm posting to Paypal: <input type="hidden" name="on0" value="Term"> <select name="os0"> <option value="1 Year">1 Year</option> <option value="3 Years">3 Years</option> <option value="5 Years">5 Years</option> </select> Edited November 3, 2019 by jakebur01 Hello guys I've hit a problem whicle trying to validate my form. I have 3 drop down boxes where the user chooses from three options. But I can't seem to figure out how to set the validation so the user does not select the same option in each drop down. Can anyone help me solve this please. Thank you. <p><b>Course Choice 1</b> <select name="course1"> <option value="0"></option> <option value="Business computer Systems">Business computer Systems</option> <option value="Business computer Science">Business computer Science</option> <option value="Business computer Science (Games)">Business computer Science (Games)</option> <option value="Business Information Systems">Business Information Systems</option> <option value="Digital Media Development">Digital Media Development</option> <option value="Digital Media">Digital Media</option> </select></p> <p><b>Course Choice 2</b> <select name="course2"> <option value="Leave Blank">Leave Blank</option> <option value="Business computer Systems">Business computer Systems</option> <option value="Business computer Science">Business computer Science</option> <option value="Business computer Science (Games)">Business computer Science (Games)</option> <option value="Business Information Systems">Business Information Systems</option> <option value="Digital Media Development">Digital Media Development</option> <option value="Digital Media">Digital Media</option> </select></p> <p><b>Course Choice 3</b> <select name="course3"> <option value="Leave Blank">Leave Blank</option> <option value="Business computer Systems">Business computer Systems</option> <option value="Business computer Science">Business computer Science</option> <option value="Business computer Science (Games)">Business computer Science (Games)</option> <option value="Business Information Systems">Business Information Systems</option> <option value="Digital Media Development">Digital Media Development</option> <option value="Digital Media">Digital Media</option> </select></p> <div align="centre"><input type="submit" name="submit" value="send request" /></div> //Validate course choice 1 if (!empty($_REQUEST['course1'])) { $course1 = $_REQUEST['course1']; } else { $course1 = NULL; echo '<p><font color="red">Please enter your first choice</font></p>'; } //Validate course choice 2 if (!empty($_REQUEST['course2'])) { $course2 = $_REQUEST['course2']; } else { $course2 = NULL; echo '<p><font color="red">Please enter your second choice</font></p>'; } //Validate course choice 3 if (!empty($_REQUEST['course3'])) { $course3 = $_REQUEST['course3']; } else { $course3 = NULL; echo '<p><font color="red">Please enter your third choice</font></p>'; } //If everything is ok, print the message if ($name && $email && $course1 && $course2 && $course3) { echo "<p>Thank you, <b>$name</b>, You have chosen the following courses for information:<br /><br /> <b>$course1</b><br /> <b>$course2</b><br /> <b>$course3</b></p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // One form element was not filled out properly echo '<p><font color="red">Please go back and fill out the form again.</font></p>'; } Hi, I'm a php newbie, with some mysql experience. I have a mysql database as follows: Database=watch, Table=events - fields id, reportno, sdate, comments What I need is: 1. A dropdown list to display reportno from mysql database. 2. Depending on which reportno I choose, I'd like to open a popup(or separate) page to display the stored information. Tks in advance for any help Hi,
I am looking for a tutorial or code sample I can use to learn MySQLi pagination with an option to select items per page, like the attached screenshort.
Any help is grately appreciated.
Regards.
joseph
Attached Files
table-pagination.jpg 32.87KB
0 downloads |