Jump to content

newphpcoder

Members
  • Posts

    254
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

newphpcoder's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. Hi, It's my first time to used foreach loop to display data from database and also used foreach loop to display textboxes Now, I felt difficulties in saving data from the textboxes displayed by foreach. Here is my code: <html> <head> </head> <body> <form name="operator_report" action="" method="post" autocomplete="off"> <?php ob_start(); include "connection.php"; $save = isset($_POST['save']); //insert data to database if($save) { $compound_type = $_POST['compound_type']; $op_output = $_POST['output']; $c_output = $_POST['output']; $reject_type[] = $_POST['reject_type']; $reject[] = $_POST['reject']; for($s = 0; $s < count($compound_type) ; $s++) { //---save operators output to op_output, in this part i don't have problem in saving the data saved correctly if ($op_output[$s] !="") { $sql = "INSERT INTO op_output (op_number, process_id, shift_id, shift_date, shift_type, compound_type, compound_output) VALUES ('001', '4', '1','2013-07-16', '1', '$compound_type[$s]', '$op_output[$s]')"; $result = mysql_query($sql, $con); } //---this part I need help in saving reject. //---I guess i have the problem here in looping ... //---this code did not work.. for($i = 0; $i < count($reject_type[$s]) ; $i++) { if($reject[$i] != "") { $sql_re = "INSERT INTO op_reject (op_number, compound_type, reject_type, reject) VALUES ('001','$compound_type[$s]', '$reject_type[$i]', '$reject[$i]')"; $result_re = mysql_query($sql_re, $con); } } } } $id = 'Final Mix'; if($id == 'Final Mix') { echo "<fieldset>"; echo "<legend><H1> Operator's Output and Reject</H1></legend>"; echo "<table>"; echo "<tr>"; echo "<th>Compound</th>"; echo "<th>Output</th>"; //query to select reject acronym $sql = "select r.reject_acro, r.reject_id from process_list AS p LEFT JOIN reject_list AS r ON p.reject_id = r.reject_process_id where p.process_name LIKE '" .$id. "%'"; $rsd = mysql_query($sql); while($rs = mysql_fetch_assoc($rsd)) { $reject[] = $rs['reject_acro']; $reject_id[] = $rs['reject_id']; } if(empty($reject)) { echo""; } else { //display reject acronym as header foreach ($reject as $reject) { echo "<th style='border:none;'><input type='text' name='reject_type[]' id='reject_type' value='$reject' style='border:none; font-weight: bold; ' size='5'></th>"; } echo "</tr>"; } //query select compound_type $sql_comp = "SELECT compound_id, compound_type FROM compound_list ORDER BY compound_type ASC"; $res = mysql_query($sql_comp); echo "<tr>"; while($comp = mysql_fetch_assoc($res)){ $compound_type = $comp['compound_type']; //---display compound_type echo "<td style='border:none;'><input type='text' name='compound_type[]' id='compound_type' value='$compound_type' style='border:none;' size='10'readonly='readonly'></td>"; //---input box for output echo "<td style='border:none;'><input type='text' name='output[]' id='output' value='' size='7'></td>"; //----i used foreach to loop textbox in every reject acronym. foreach($reject_id AS $reject) { echo "<td style='border:none;'><input type='text' name='reject[]' id='reject' value='' size='7'></td>"; } echo "</tr>"; } echo "</table>"; echo "</fieldset>"; } ?> <input type="submit" name="save" id="save" value="Save"> </form> </body> </html> I also attached my sample output screenshots and the database. Here is the sample scenario. Compound Type---Output---SC---SP---SH--- P28--------------10-------------1-----2 P32--------------20--------5--------------- P32NW--------------------------3---------- I need to save data on op_reject like this: op_number---compound_type----reject_type---reject 001----------P28---------------SP------------1 001----------P28---------------SH------------2 001----------P32---------------SC------------5 001----------P32NW------------SP------------3 Sad to say in my code in saving using forloop it did not work. I post it because i am hoping somebody can help me, but I also tried my best to fixed this. Any help is highly appreciated. Thank you so much. sample.zip
  2. Hi, I have data: shift_id = 1---2---3---4---5 compound_output = 5---10--20--50--10 process_id = 7 compound_type = P28 and now I need to create a query that sum the value of (1+3+(5/ 2)) and (2+4+(5/ 2)) here is my query: SELECT process_id, compound_type, CASE WHEN (shift_id IS NOT NULL AND (shift_id = 1 OR shift_id = 3 OR shift_id = 5)) THEN SUM((compound_output)/2) when (shift_id IS NOT NULL AND (shift_id = 2 OR shift_id = 4 OR shift_id = 5)) THEN SUM((compound_output)/2) END AS val FROM op_output WHERE process_id = 7 and compound_type = 'P28' HAVING val IS NOT NULL and the output of this is: val = 47.500000 but it should be: 7---P28--30 7---P28--65 Thank you so much.. I hope somebody can help me to get the correct values. Thank you so much.
  3. Hi, I have form that displaying report per week. First thing to do is choose what week then automatically display the date/shift that week ranges. here is my weekly_report.php <?php error_reporting(0); session_start(); ob_start(); date_default_timezone_set("Asia/Singapore"); include('connection.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <title>Weekly Report</title> <head> <link rel="stylesheet" type="text/css" href="op_report.css" /> <script type="text/javascript" src="jquery.js"></script> <script type='text/javascript' src='jquery.autocomplete.js'></script> <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" /> <script type="text/javascript"> //----auto complete week--// $().ready(function() { $("#week_selected").autocomplete("get_week_list.php", { width: 115, matchContains: true, mustMatch: true, selectFirst: false }); $("#week_selected").result(function(event, data, formatted) { $("#week_number").val(data[1]); }); }); /*AJAX*/ function AJAX(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari return xmlHttp; } catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer return xmlHttp; } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); return xmlHttp; } catch (e){ alert("Your browser does not support AJAX!"); return false; } } } } //-----get weekdata from week---// function getweekdata() { // if (window.event.keyCode==13 || window.event.keyCode==10) { divid = "week_data"; var url = "get_weekly_data.php"; var str = "id=" + document.getElementById("week_number").value; var xmlHttp = AJAX(); xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){ // document.getElementById(divid).innerHTML=loadingmessage; } if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { var jsonart = xmlHttp.responseText; document.getElementById(divid).innerHTML = jsonart; } } } xmlHttp.open("POST", url, true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", str.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(str); // } } </script> </head> <body onload=document.getElementById("week_selected").focus();> <form name="weekly_report" action="" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="index.php" title="Operator's Shift Report"><span>Operator's Shift Report</span></a></li> <li id="current"> <a href="weekly_report.php" title="Reports"><span>Reports</span></a></li> </ul> </div> <br/> <div> <table> <tr> <td style="border: none;">Type Week:</td> <td><input type="text" name="week_selected" id="week_selected" value="" size="15" onkeyup="getweekdata();"></td> </tr> </table> </div> <input type="hidden" name="week_number" id="week_number"> <div id='week_data'> </div> </form> </body> </html> //get_week_list.php <?php ob_start(); include "connection.php"; $q = strtolower($_GET["q"]); if ($q == '') { header("HTTP/1.0 404 Not Found", true, 404); } //else (!$q) return; else{ $sql = "select week_id, week_number from week_list where week_number LIKE '$q%'"; $rsd = mysql_query($sql); $cnt = mysql_num_rows($rsd); if($cnt > 0) { while($rs = mysql_fetch_array($rsd)) { $pid = $rs['week_id']; $pname = $rs['week_number']; echo "$pname|$pid\n"; } } else { header("HTTP/1.0 404 Not Found", true, 404); } } ?> and here is my get_weekly_data.php // which display the data for that week. <?php ob_start(); include "connection.php"; if($_POST["id"]) { $sql = "select r.report_date, s.shift_type FROM op_reports AS r, shift_list AS s WHERE WEEK(report_date) + 1 = '" . ($_POST["id"]) . "' GROUP BY shift_type ORDER BY shift_id ASC"; $res = mysql_query($sql); echo "<table>"; echo "<tr>"; echo "<th>Comp</th>"; while($row = mysql_fetch_assoc($res)) { $report_date = $row['report_date']; $report_shift = $row['shift_type']; echo "<th>$report_date/$report_shift</th>"; } echo "</tr>"; $sql_r = "select r.report_date, s.shift_type FROM op_reports AS r, shift_list AS s WHERE WEEK(report_date) + 1 = '" . ($_POST["id"]) . "' GROUP BY shift_type ORDER BY shift_type DESC"; $res_r = mysql_query($sql_r); echo "<tr>"; echo "<th></th>"; while($r = mysql_fetch_assoc($res_r)){ echo "<th>Output</th>"; } echo "</tr>"; $sql_comp = "SELECT DISTINCT p.process_name , r.process_id, r.report_shift FROM op_reports AS r JOIN process_list AS p ON (p.process_id = r.process_id) WHERE WEEK(report_date) + 1 = '" . ($_POST["id"]) . "' GROUP BY process_name ORDER BY p.process_name ASC"; $res_comp = mysql_query($sql_comp); echo "<tr>"; while($row_comp = mysql_fetch_assoc($res_comp)) { $process = $row_comp['process_name']; $process_id = $row_comp['process_id']; echo "<td>$process</td>"; $comp = "SELECT DISTINCT o.compound_type, o.process_id, o.shift_date FROM op_output AS o WHERE process_id = '$process_id' GROUP BY o.shift_id, compound_type ORDER BY compound_type ASC"; $c = mysql_query($comp); echo "<tr>"; while($co = mysql_fetch_assoc($c)) { $compound_type = $co['compound_type']; $process_i = $co['process_id']; $shift_date = $co['shift_date']; echo "<td>$compound_type</td>"; $sql_output = "SELECT DISTINCT o.compound_type, SUM(o.compound_output) AS compound_output, o.process_id, o.shift_id, o.shift_date FROM op_output AS o WHERE process_id = '$process_id' AND o.compound_type = '$compound_type' GROUP BY o.shift_id, o.shift_date, compound_type ORDER BY o.shift_id ASC"; $res_output = mysql_query($sql_output); while($row_output = mysql_fetch_assoc($res_output)) { $compound_output = $row_output['compound_output']; $shift = $row_output['shift_id']; $compound = $row_output['compound_type']; $date = $row_output['shift_date']; if($shift == 1 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 2 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 3 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 4 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 5 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } } echo "</tr>"; } } echo "</tr>"; echo "</table>"; } ?> I attached my sample screenshots that display by this code and also a format that I need to display and the database. My problem now is on displaying of output per date/shift. It's been todays that I tried to fixed this. I hope somebody can help me. Thank you so much sample updated.zip
  4. Hi.. I have 2 tables for week and calendar days. first I have so_week fields: from_week to_week second is calendar_days fields: month_name working_days sample data: from_week : 33 to_week: 36 month_name: Jan Feb Mar Apr May and so on working_days: 23 22 25 25 23 now I need to get the working days based on from_week to week for example from 33 to 36 the month is aug, sep, sep, sep i need to get the working days for that month. any help is highly appreciated.. Thank you so much
  5. Theirs a data output but not my expected output. Thank you
  6. Hi.. I have problem in my select query statement with case statement to compute the qty and I tried evetything to resolved my problem. here is my query: first I tried the requirement qty is less than in balance qty. @rqty = requirement qty @q= balalce qty set @t = 0; set @rqty = 900; set @r = 563; set @q = 966; SELECT SUBSTR(d.LOT_CODE, 9,4) as pcode, d.LOT_CODE as code, d.OUTPUT_QTY, d.DATE_ENTRY, CASE WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty THEN j.bal_qty WHEN d.LOT_CODE = j.lotcode AND @rqty < j.bal_qty THEN @rqty WHEN @rqty < @t + d.OUTPUT_QTY THEN (@rqty - @q) WHEN @t+d.OUTPUT_QTY > @rqty THEN (@rqty - @q) ELSE d.OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping_dump d, dependency c, jo_last j WHERE NOT EXISTS (SELECT j.lotcode, j.pcode FROM jo_dump j WHERE j.lotcode = d.LOT_CODE AND j.pcode = SUBSTR(d.LOT_CODE, 9,4) AND j.qty = d.OUTPUT_QTY) AND c.LOT_CODE = d.LOT_CODE AND c.DATE_ENTRY = d.DATE_ENTRY AND c.TERMINAL_ID = '5' AND c.ACTIVE = '1' AND SUBSTR(d.LOT_CODE, 9,4) = 'P35' AND (@t < @rqty) AND j.STATUS = '1' ORDER BY d.DATE_ENTRY ASC; I attached the sample image output. I got a problem when the requirement qty is less than output qty and greater balance qty. I hope this time someone can understand and help me. Thank you so much..
  7. Hi... I need to get data from two tables but i need to based first on jo_last to check if theirs an bal_qty so that I need to get first the bal_qty before I get the output qty from dipping_dump table to get my req qty. here is my query where the rqty is > OUTPUT_QTY : set @t = 0; set @rqty =2401; set @r = 563; set @q = 966; SELECT SUBSTR(d.LOT_CODE, 9,4) as pcode, d.LOT_CODE as code, d.OUTPUT_QTY, d.DATE_ENTRY, CASE WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty THEN j.bal_qty WHEN d.LOT_CODE = j.lotcode AND @rqty < j.bal_qty THEN @rqty WHEN @t+d.OUTPUT_QTY > @rqty THEN (@rqty - @q) WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty AND @rqty < d.OUTPUT_QTY THEN j.bal_qty ELSE d.OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping_dump d, dependency c, jo_last j WHERE NOT EXISTS (SELECT j.lotcode, j.pcode FROM jo_dump j WHERE j.lotcode = d.LOT_CODE AND j.pcode = SUBSTR(d.LOT_CODE, 9,4) AND j.qty = d.OUTPUT_QTY) AND c.LOT_CODE = d.LOT_CODE AND c.DATE_ENTRY = d.DATE_ENTRY AND c.TERMINAL_ID = '5' AND c.ACTIVE = '1' AND SUBSTR(d.LOT_CODE, 9,4) = 'P35' AND (@t < @rqty) AND j.STATUS = '1' ORDER BY d.DATE_ENTRY ASC; in this example the output is correct: pcode----code-------------OUTPUT_QTY-DATE_ENTRY------------qty-----cumulative P35------ 10172710P35- 2000.00-------2012-07-11 09:46:18-966.00-2000.00 P35------ 027723883P35-2000.00------2012-07-11 09:46:44-1435----2000.00 this output is correct this code : 10172710P35 has a balance 966.00 so right that i get first this 966 in jo_last and the lack i get in dipping_dump to get the total req qty 2401. and here is the sample where the rqty is < to bal_qty set @t = 0; set @rqty =900; set @r = 563; set @q = 966; SELECT SUBSTR(d.LOT_CODE, 9,4) as pcode, d.LOT_CODE as code, d.OUTPUT_QTY, d.DATE_ENTRY, CASE WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty THEN j.bal_qty WHEN d.LOT_CODE = j.lotcode AND @rqty < j.bal_qty THEN @rqty WHEN @t+d.OUTPUT_QTY > @rqty THEN (@rqty - @q) WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty AND @rqty < d.OUTPUT_QTY THEN j.bal_qty ELSE d.OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping_dump d, dependency c, jo_last j WHERE NOT EXISTS (SELECT j.lotcode, j.pcode FROM jo_dump j WHERE j.lotcode = d.LOT_CODE AND j.pcode = SUBSTR(d.LOT_CODE, 9,4) AND j.qty = d.OUTPUT_QTY) AND c.LOT_CODE = d.LOT_CODE AND c.DATE_ENTRY = d.DATE_ENTRY AND c.TERMINAL_ID = '5' AND c.ACTIVE = '1' AND SUBSTR(d.LOT_CODE, 9,4) = 'P35' AND (@t < @rqty) AND j.STATUS = '1' ORDER BY d.DATE_ENTRY ASC; and the output is correct: pcode----code-------------OUTPUT_QTY-DATE_ENTRY------------qty-----cumulative P35------ 10172710P35- 2000.00-------2012-07-11 09:46:18-900.00-2000.00 as you can see same query i only change the rqty to check if the output is correct. but when i tried this: set @t = 0; set @rqty =1501; set @r = 563; set @q = 966; SELECT SUBSTR(d.LOT_CODE, 9,4) as pcode, d.LOT_CODE as code, d.OUTPUT_QTY, d.DATE_ENTRY, CASE WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty THEN j.bal_qty WHEN d.LOT_CODE = j.lotcode AND @rqty < j.bal_qty THEN @rqty WHEN @t+d.OUTPUT_QTY > @rqty THEN (@rqty - @q) WHEN d.LOT_CODE = j.lotcode AND @rqty > j.bal_qty AND @rqty < d.OUTPUT_QTY THEN j.bal_qty ELSE d.OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping_dump d, dependency c, jo_last j WHERE NOT EXISTS (SELECT j.lotcode, j.pcode FROM jo_dump j WHERE j.lotcode = d.LOT_CODE AND j.pcode = SUBSTR(d.LOT_CODE, 9,4) AND j.qty = d.OUTPUT_QTY) AND c.LOT_CODE = d.LOT_CODE AND c.DATE_ENTRY = d.DATE_ENTRY AND c.TERMINAL_ID = '5' AND c.ACTIVE = '1' AND SUBSTR(d.LOT_CODE, 9,4) = 'P35' AND (@t < @rqty) AND j.STATUS = '1' ORDER BY d.DATE_ENTRY ASC; the output is: pcode----code-------------OUTPUT_QTY-DATE_ENTRY------------qty-----cumulative P35------ 10172710P35- 2000.00-------2012-07-11 09:46:18-966.00-2000.00 and this correct but lack of output. it should be: pcode----code-------------OUTPUT_QTY-DATE_ENTRY------------qty-----cumulative P35------ 10172710P35- 2000.00-------2012-07-11 09:46:18-966.00-2000.00 P35------ 027723883P35-2000.00------2012-07-11 09:46:44-535----2000.00 to get the 1501 rqty. I tried to fix it, yet the output is wrong so I decided to post my problem in forum. Any help is highly appreciated. Thank you so much
  8. Hi.. Now, I have select query with if condition, that if null the table data <td> will have background-color : red here is my code: $sql = "SELECT DISTINCT IF(ISNULL(a.LOG_IN), 'rdc', '') AS LOGIN_CLASS, IF(ISNULL(a.LOG_OUT), 'rdc', '') AS LOGOUT_CLASS, a.EMP_ID, a.LOG_IN, a.LOG_OUT, CONCAT(LNAME, ',' , FNAME, ' ', MI, '.') AS FULLNAME FROM hrdb.attendance AS a JOIN hris.employment em ON (a.EMP_ID = em.EMP_NO AND em.STATUS = 'Reg Operatives') JOIN hris.personal AS p ON p.EMP_ID = em.EMP_ID WHERE ATTENDANCE_DATE BETWEEN '2012-06-01' AND '2012-06-15' OR ATTENDANCE_DATE = '0000-00-00' OR ISNULL(a.LOG_IN) OR ISNULL(a.LOG_OUT) ORDER BY FULLNAME, a.LOG_IN, a.LOG_OUT"; $DTR = $conn3->GetAll($sql); $smarty->assign('attendance', $DTR); .rdc {background-color:#ff0000;} {section name=att loop=$attendance} <table> <tr> <td colspan="2" class="{$attendance[att].LOGIN_CLASS}">{$attendance[att].LOG_IN}</td> <td colspan="2" class="{$attendance[att].LOGOUT_CLASS}">{$attendance[att].LOG_OUT}</td> {sectionelse} <tr><td colspan="1">No DATA</td></tr> {/section} Now.. I need to revise my select if condition, because now the LOG_IN and LOG_OUT has no possibilities to have NULL values but now It will have 0000-00-00 00:00:00 values. So I need to put background color if the LOG_IN is 0000-00-00 00:00:00 also with LOG_OUT. Thank you so much
  9. Hi.. I have 2 tables with Cloth column. sales_order table Cloth -column sample data of Cloth 3392 3520 3392 Yellow/White 3392 BLUE 3392 RED 3392 Orange cloth_parameter - table Cloth -column sample Cloth 3392N 3520 3392Yellow/White 3392 Blue 3392 Red 3392Orange How can I equal the two data eventhough the format of data has difference using like. Thank you
  10. Thank you for your suggested links, but sorry, it's a jquery and I also dont have any idea about jquery, my goal today is to resolve this problem that I encountered. Thank you so much. I think my issue is on how can I get using ajax the value of selected option. Thank you
  11. Hi... It's my first time to use ajax and I used it to get the bin_loc per lot_number where I choose in select option per ItemCode. And now I get the bin_loc but the problem is I only get the bin_loc of the first select option the rest was not. Here is my code of PickingForm.php <?php session_start(); 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); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <title>Picking</title> <head> <link href="kanban.css" rel="stylesheet" type="text/css"> <script type="text/javascript"> var xmlhttp; // Give the function a unique name, this is what your HTML will call to run the AJAX function select_code() { // This is all just setting up the variable, ignore it if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { //alert(xmlhttp.responseText); // alert(xmlhttp.readyState+" "+xmlhttp.status); // alert(xmlhttp.readyState+" "+xmlhttp.status); document.getElementById("bin_loc").innerHTML = xmlhttp.responseText; //var mydata=xmlhttp.responseText; } }; var val = document.getElementById("lot_number"); var lot_number = val.options[val.selectedIndex].text; //alert(lot_number); var parameters = "lot_number=" + lot_number; xmlhttp.open("POST", "PickingFormTest.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(parameters); //var mydata=xmlhttp.responseText; } </script> </head> <body> <div id="SR_date"> <label>Date :</label> <input type="text" name="date_pick" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="Picking"> <?php $sr_num_ = $_POST['sr_num_']; //$sql = "SELECT sr_number " $sql = "SELECT sr_number, Items, DemandedQty, uom FROM sr_main WHERE sr_number = '$sr_num_'"; $res_sr_main = mysql_query($sql, $con); $row_num = mysql_num_rows($res_sr_main); if($row_num > 0){ while($row_sr_main = mysql_fetch_assoc($res_sr_main)){ $sr_number_ = $row_sr_main['sr_number']; $items = $row_sr_main['Items']; $demandedqty = $row_sr_main['DemandedQty']; $uom = $row_sr_main['uom']; echo "<label> SR # :</label>"; echo "<input type='text' readonly='readonly' style='border:none;' id='sr_number_' name='sr_number_' value='$sr_number_'>"; echo "<table>"; echo "<th>Items</th> <th> Item Code </th> <th> Demanded Qty </th> <th> UoM </th> <th> Description </th> <th> Lot Number </th> <th> Bin Location </th> <th> Picked By </th> <th> Approved</th>"; echo "<tr> <td>$items</td> <td></td> <td style='text-align:right;'>$demandedqty</td> <td>$uom</td> </tr>"; $sql_sub = "SELECT s.sr_number, s.Items, s.ItemCode, s.SubQty, s.UoM, s.Description FROM sr_submain s WHERE s.sr_number = '$sr_num_' and s.Items = '$items' AND NOT EXISTS(SELECT w.stock_item FROM wms w WHERE s.ItemCode = w.stock_item AND w.sr_number = s.sr_number AND (w.qty_withdraw !='0.00' OR w.qty_withdraw = 'NULL'))"; $res_sub = mysql_query($sql_sub, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<form name='picking_lotnum' action='PickingForm.php?sr_num_=".$sr_num_."' method='POST' enctype='multipart/form-data' target='_self'>"; $sr_num = $row_sub['sr_number']; $Items = $row_sub['Items']; $ItemCode = $row_sub['ItemCode']; $SubQty = $row_sub['SubQty']; $UoM = $row_sub['UoM']; $Description = $row_sub['Description']; $query = "SELECT lot_number from wms WHERE (date_shelve IS NOT NULL) AND stock_item = '$ItemCode' AND (qty = orig_qty OR qty != '0.00') AND qty >= '$SubQty' ORDER BY qty"; $rows = mysql_query($query, $con); echo "<tr> <td></td> <td><input type='text' name='ItemCode' id='ItemCode' value='$ItemCode' readonly='readonly' style='border:none;font-family: Arial, Helvetica, sans-serif; font-size: .9em;'></td> <td><input type='text' name='SubQty' id='SubQty' value='$SubQty' readonly = 'readonly' style='border:none; text-align:right;font-family: Arial, Helvetica, sans-serif; font-size: .9em;'></td> <td>$UoM</td> <td>$Description</td>"; echo "<td><select name = 'lot_number' id='lot_number' onChange='select_code();'>"; echo "<option></option>"; while ($record = mysql_fetch_array($rows)) { echo "<option value = '{$record['lot_number']}'"; if ($lot_number == $record['lot_number']) echo "selected = 'selected'"; echo ">{$record['lot_number']}</option>"; } echo "</select>"; echo "</td>"; echo "<td id='bin_loc'></td>"; echo "<td> <input type='text' name='picked_by' id='picked_by' size='20' value=''> </td>"; echo "<td><input type='submit' name='priority' value='Approved' id='priority'></td>"; echo "</tr>"; echo "<input type='hidden' name='date_pick' value='$Date_Shelve' size='16' style='border: none;'>"; echo "<input type='hidden' readonly='readonly' style='border:none;' id='sr_num_' name='sr_num_' value='$sr_number_'>"; echo "</form>"; } } } echo "</table>"; echo "</div>"; ?> </body> </html> and here is the PickingFormTest.php <?php session_start(); 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); $lot_number = $_POST['lot_number']; //echo $lot_number; // $q=$_GET["lot_number"]; $sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'"; $res_bin = mysql_query($sql_bin, $con); while($row_bin = mysql_fetch_assoc($res_bin)){ $bin_loc = $row_bin['bin_loc']; echo "<input type='text' value='$bin_loc' id='bin_loc'>"; } ?> I attach the sample form Thank you so much
  12. Hi.. It's my first time to use ajax, and now I used ajax to get the value from select option then use that value. here is my ajax code: <script type="text/javascript"> var xmlhttp; // Give the function a unique name, this is what your HTML will call to run the AJAX function select_code() { // This is all just setting up the variable, ignore it if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { //alert(xmlhttp.responseText); // alert(xmlhttp.readyState+" "+xmlhttp.status); document.getElementById("rows").innerHTML = xmlhttp.responseText; //var mydata=xmlhttp.responseText; } }; var val = document.getElementById("lot_number"); var lot_number = val.options[val.selectedIndex].text; var parameters = "lot_number=" + lot_number; xmlhttp.open("POST", "PickingForm.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(parameters); //var mydata=xmlhttp.responseText; } </script> nad here is my PickingForm.php where the select option was in. $query = "SELECT lot_number from wms WHERE (date_shelve IS NOT NULL) AND stock_item = '$ItemCode' AND (qty = orig_qty OR qty != '0.00') AND qty >= '$SubQty' ORDER BY qty"; $rows = mysql_query($query, $con); echo "<td><select name = 'lot_number' id='lot_number' onChange='select_code();'>"; //echo "<select name='lot_number' id='lot_number' onchange='MM_jumpMenu('parent',this,0)'>"; echo "<option></option>"; while ($record = mysql_fetch_array($rows)) { echo "<option value = '{$record['lot_number']}'"; if ($lot_number == $record['lot_number']) echo "selected = 'selected'"; echo ">{$record['lot_number']}</option>"; } echo "</select>"; echo "</td>"; $lot_number = $_POST['lot_number']; $sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'"; $res_bin = mysql_query($sql_bin, $con); while($row_bin = mysql_fetch_assoc($res_bin)){ $bin_loc = $row_bin['bin_loc']; echo "<td><input type='text' name='bin_loc' id='bin_loc' value='$bin_loc'></td>"; } and when I select lot_code in select option: I got an error: document.getElementById() is null or not an object... I don't know how can I solve this error:( Thank you
  13. Thank you.. I don't know about ajax can you help me:( Thank you
  14. how can I do that?can you give me a example: here is my whole code: <?php session_start(); 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); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <title>Picking</title> <head> <link href="kanban.css" rel="stylesheet" type="text/css"> <script type="text/javascript"> function getText(){ var x=document.getElementById("lot_number") //alert(x.options[x.selectedIndex].text); var lot_number = (x.options[x.selectedIndex].text); document.picking_form.action="PickingForm.php?lot_number="+lot_number; document.picking_form.submit(); } </script> </head> <body> <?php $Approved = isset($_POST['priority']); if ($Approved) { $lot_number = $_POST['lot_number']; $sr_num_ = $_POST['sr_num_']; $SubQty = $_POST['SubQty']; $ItemCode = $_POST['ItemCode']; $picked_by = $_POST['picked_by']; $date_pick = $_POST['date_pick']; $sql = "SELECT stock_item, qty FROM wms WHERE stock_item = '" . $ItemCode . "' AND lot_number = '" . $lot_number . "'"; $res = mysql_query($sql, $con) or die( "Query : [$sql]<br/>\nError : ". mysql_error($con)); $row = mysql_fetch_assoc($res); $stock_item = $row['stock_item']; $qty = $row['qty']; if($qty >= $SubQty){ $output = $qty - $SubQty; $qty_withdraw = '0.00'; } else{ $output = '0.00'; $qty_withdraw = $SubQty - $qty; } $sql_up = "UPDATE wms SET qty = '$output', sr_number = '$sr_num_', picked_by = '$picked_by', qty_withdraw = '$qty_withdraw', date_pick = '$date_pick' WHERE lot_number = '$lot_number' AND stock_item = '$ItemCode'"; //echo $sql_up; //exit; $res_up = mysql_query($sql_up, $con) or die( "Query : [$sql_up]<br/>\nError : ". mysql_error($con)); } else{ } ?> <div id="SR_date"> <label>Date :</label> <input type="text" name="date_pick" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="Picking"> <!--<label class="LLabellot">Select SR # :</label>--> <?php $sr_num_ = $_POST['sr_num_']; $sql = "SELECT sr_number, Items, DemandedQty, uom FROM sr_main WHERE sr_number = '$sr_num_'"; $res_sr_main = mysql_query($sql, $con); $row_num = mysql_num_rows($res_sr_main); if($row_num > 0){ while($row_sr_main = mysql_fetch_assoc($res_sr_main)){ $sr_number_ = $row_sr_main['sr_number']; $items = $row_sr_main['Items']; $demandedqty = $row_sr_main['DemandedQty']; $uom = $row_sr_main['uom']; echo "<label> SR # :</label>"; echo "<input type='text' readonly='readonly' style='border:none;' id='sr_number_' name='sr_number_' value='$sr_number_'>"; echo "<table>"; echo "<th>Items</th> <th> Item Code </th> <th> Demanded Qty </th> <th> UoM </th> <th> Description </th> <th> Lot Number </th> <th> Bin Location </th> <th> Picked By </th> <th> Approved</th>"; echo "<tr> <td>$items</td> <td></td> <td style='text-align:right;'>$demandedqty</td> <td>$uom</td> </tr>"; $sql_sub = "SELECT s.sr_number, s.Items, s.ItemCode, s.SubQty, s.UoM, s.Description FROM sr_submain s WHERE s.sr_number = '$sr_num_' and s.Items = '$items' AND NOT EXISTS(SELECT w.stock_item FROM wms w WHERE s.ItemCode = w.stock_item AND w.sr_number = s.sr_number AND (w.qty_withdraw !='0.00' OR w.qty_withdraw = 'NULL'))"; $res_sub = mysql_query($sql_sub, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<form name='picking_lotnum' action='PickingForm.php?sr_num_=".$sr_num_."' method='POST'>"; $sr_num = $row_sub['sr_number']; $Items = $row_sub['Items']; $ItemCode = $row_sub['ItemCode']; $SubQty = $row_sub['SubQty']; $UoM = $row_sub['UoM']; $Description = $row_sub['Description']; $query = "SELECT lot_number from wms WHERE (date_shelve IS NOT NULL) AND stock_item = '$ItemCode' AND (qty = orig_qty OR qty != '0.00') AND qty >= '$SubQty' ORDER BY qty"; $rows = mysql_query($query, $con); echo "<tr> <td></td> <td><input type='text' name='ItemCode' id='ItemCode' value='$ItemCode' readonly='readonly' style='border:none;font-family: Arial, Helvetica, sans-serif; font-size: .9em;'></td> <td><input type='text' name='SubQty' id='SubQty' value='$SubQty' readonly = 'readonly' style='border:none; text-align:right;font-family: Arial, Helvetica, sans-serif; font-size: .9em;'></td> <td>$UoM</td> <td>$Description</td>"; echo "<td><select name = 'lot_number' id='lot_number'>"; echo "<option></option>"; while ($record = mysql_fetch_array($rows)) { echo "<option value = '{$record['lot_number']}'"; if ($lot_number == $record['lot_number']) echo "selected = 'selected'"; echo ">{$record['lot_number']}</option>"; } echo "</select>"; echo "</td>"; $lot_number = $_POST[lot_number]; $sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'"; $res_bin = mysql_query($sql_bin); $row_bin = mysql_fetch_assoc($res_bin); $bin_loc = $row_bin['bin_loc']; echo $bin_loc; echo "<td>$bin_loc</td>"; //echo "<td>$bin_loc</td>"; echo "<td> <input type='text' name='picked_by' id='picked_by' size='20' value=''> </td>"; // echo "<td><input type='checkbox' name='chk_[]' value='$ItemCode' onclick = 'chk();' id='chk_'></td> echo "<td><input type='submit' name='priority' value='Approved' id='priority'></td>"; echo "</tr>"; echo "<input type='hidden' name='date_pick' value='$Date_Shelve' size='16' style='border: none;'>"; echo "<input type='hidden' readonly='readonly' style='border:none;' id='sr_num_' name='sr_num_' value='$sr_number_'>"; echo "</form>"; } } } echo "</table>"; echo "</div>"; ?> </body> </html> Thank you so much.. I tried this: if(isset($_POST['lot_number'])) { $lot_number=mysql_real_escape_string($_POST['lot_number']); echo $lot_number; $sql_bin = "SELECT bin_loc FROM wms WHERE lot_number = '$lot_number'"; echo $sql; $res_bin = mysql_query($sql_bin, $con); $row_bin = mysql_fetch_assoc($res_bin); $bin_loc = $row_bin['bin_loc']; echo $bin_loc; but no output display Thank you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.