Jump to content

need help in displaying form inside foreach


Recommended Posts

Hi.I created forms with condition to only view Items which is = Min Lot, now my problem is if no items that = Min Lot the select option below was displayed and the save button. I want to display them only also if the if condition is true. I mean if the condition was not satisfied no display, now in my code it happened is the Issued BY, Received By, Approved BY, Requested By and save button was still display.. How can I also display only them if the condition was satisfied?Thank youhere is my code:

<?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); ?><html><title>Stock Requisition</title><head><link rel="stylesheet" type="text/css" href="kanban.css"> <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;    var Items1 = document.getElementById("Items1").value;    var SubQty_ = document.getElementsByTagName('input');    var SubQty = SubQty_[9].getAttribute("value");    var sr_number_hide = document.getElementById("sr_number_hide").value;     document.frmMain.action="StockRequisitionSave1.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+"&Items1="+Items1+"&sr_number_hide="+sr_number_hide+"&SubQty="+SubQty;    document.frmMain.submit();   alert("Stock Requisition data save.");   //window.location = "StockRequisition1.php";   window.location = "StockRequisitionDisplay1.php";}</script><script type="text/javascript">function test_(cmpd, mult) {	 var len_ = (document.frmMain.elements.length) - 1;	 for (i=0; i <= len_; i++ ) {	   var cmp = "_" + cmpd;   	   var strPos_ = document.frmMain.elements[i].id.indexOf(cmp)					  if (strPos_ != -1) {			  var strPos = document.frmMain.elements[i].id.indexOf("_");			 var strId = document.frmMain.elements[i].id.slice(strPos + 1) + "_" + document.frmMain.elements[i].id.slice(0,strPos);    document.frmMain.elements[i].value = (document.getElementById(strId).value * mult).toFixed(2);	 }    }        } </script></head><body><form name="frmMain" method="post">   <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$DemandedQty = $_POST['DemandedQty'];$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";$res_bom = mysql_query($sql, $con);$totalDistinct = mysql_num_rows($res_bom);if ($totalDistinct > 0) {    while ($row = mysql_fetch_assoc($res_bom)) {	    $Comp[] = substr($row['Items'], 12, 3);	   // $Comp = substr($cmpdArray, 12, 3);    }} foreach ($Comp as $Comp) {      $sql = "SELECT COUNT(WIP_1) AS WIP_1 FROM KANBAN_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = '$Comp' AND WIP_1 > 0";     $resultWip = mysql_query($sql, $con);    $wip_1 = mysql_result($resultWip, 0 , "WIP_1");    $wip1Accum = $wip1Accum + $wip_1;       $sql = "SELECT COUNT(WIP_2) AS WIP_2 FROM KANBAN_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = '$Comp' AND WIP_2 > 0";     $resultWip = mysql_query($sql, $con);    $wip_2 = mysql_result($resultWip, 0 , "WIP_2");    $wip2Accum = $wip2Accum + $wip_2;       $sql = "SELECT COUNT(WIP_3) AS WIP_3 FROM KANBAN_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = '$Comp' AND WIP_3 > 0";     $resultWip = mysql_query($sql, $con);    $wip_3 = mysql_result($resultWip, 0 , "WIP_3");    $wip3Accum = $wip3Accum + $wip_3;    $sql = "SELECT COUNT(WIP_4) AS WIP_4 FROM KANBAN_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = '$Comp' AND WIP_4 > 0";     $resultWip = mysql_query($sql, $con);    $wip_4 = mysql_result($resultWip, 0 , "WIP_4");    $wip4Accum = $wip4Accum + $wip_4;    $sql = "SELECT COUNT(WIP_5) AS WIP_5 FROM KANBAN_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = '$Comp' AND WIP_5 > 0";     $resultWip = mysql_query($sql, $con);    $wip_5 = mysql_result($resultWip, 0 , "WIP_5");    $wip5Accum = $wip5Accum + $wip_5;    $total = $wip_1  +  $wip_2 + $wip_3 + $wip_4 + $wip_5;   $sql = "SELECT Compounds, Min_Lot FROM param_settings WHERE Compounds = '$Comp'";$res_param = mysql_query($sql);$row_param = mysql_fetch_assoc($res_param);$Compounds = $row_param['Compounds'];$Min_Lot = $row_param['Min_Lot'];    if($Comp = $Compounds && $total == $Min_Lot){   $sql = "SELECT DISTINCT Items FROM bom_subitems WHERE SUBSTR(Items,13,3) = '$Compounds' ORDER BY Items";$res_bom = mysql_query($sql, $con);while($row = mysql_fetch_assoc($res_bom)){       $Items = $row['Items'];    $Items_ = substr($Items, 12, 3);   echo "<tr>	    <td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items_' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>	    <td style='border:none;'> </td>	    <td style='border:none;'> </td>	    <td style='border: none;'><center><input type='text' style='text-align: right;' name='DemandedQty[]' id='DemandedQty' size='12' onkeyup='test_(\"$Items_\", this.value)' value=''></center></td>		    </tr>";			$sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error());$res_sub = mysql_query($sql, $con);  $counter = 0; while($row_sub = mysql_fetch_assoc($res_sub)){	 $joinId = $counter . "_" .  $Items_;	 	 $Items = $row_sub['Items'];	 $Items1 = substr($Items, 12, 3);	 $SubItems = $row_sub['SubItems'];	 $ItemCode = $row_sub['ItemCode'];	 $UoM = $row_sub['UoM'];	 $Class = $row_sub['Class'];	 $Description = $row_sub['Description'];	 $BINLocation = $row_sub['BINLocation'];	 $Quantity = $row_sub['Quantity'];	 $joinId2 =  $Items_ . "_" . $counter;    echo "<tr>	    <td style='border: none;'> <input type='hidden' value='$Items1'  name='Items1[]' id='Items1'></td>	    <td style='border: none;'> <input type='text' name='SubItems[]' id='SubItems' value='$SubItems'  readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>	    <td style='border: none;'> <input type='text' name='ItemCode[]' id='ItemCode' value='$ItemCode'  readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>	    <td><input class='txt' type='text' name='SubQty[]' id='$joinId' readonly = 'readonly' size='12' style= 'border:none;text-align:right'/><input type='hidden' id='$joinId2' value='$Quantity' /></td>	    <td style='border: none;' size='3'> <input type='text' name='UoM[]' id='UoM' value='$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='$Class' name='Class' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>	    <td style='border: none;'> <input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td>	    <td style='border: none;'> <input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>		    </tr>";    $counter  = $counter  + 1;}}}}				?></table></div><?php   $RequestedBy = array('AAA', 'BBB', 'CCC', 'DDD');     $ApprovedBy = array('EEE', 'FFF', 'GGG', 'HHH');     $ReceivedBy = array('III', 'JJJ', 'KKK', 'LLL');     $IssuedBy = array('MMM', 'NNN', 'OOO', 'PPP');?> <div id='Requested_By'><label>Requested By:</label> <select name="RequestedBy"> <option value="Select">Select</option> <option value="AAA" <?php if($_POST['RequestedBy'] == 'AAA') echo "selected='selected'"; ?>>AAA</option>  <option value="BBB" <?php if($_POST['RequestedBy'] == 'BBB') echo "selected='selected'"; ?>>BBB</option> <option value="CCC" <?php if($_POST['RequestedBy'] == 'CCC') echo "selected='selected'"; ?>>CCC</option>  <option value="DDD" <?php if($_POST['RequestedBy'] == 'DDD') echo "selected='selected'"; ?>>DDD</option> </select></div><div id='Approved_By'><label>Approved By:</label><select name="ApprovedBy"><option name='Select'>Select</option><option value="EEE" <?php if($_POST['ApprovedBy'] == 'EEE') echo "selected='selected'"; ?>>EEE</option>  <option value="FFF" <?php if($_POST['ApprovedBy'] == 'FFF') echo "selected='selected'"; ?>>FFF</option> <option value="GGG" <?php if($_POST['ApprovedBy'] == 'GGG') echo "selected='selected'"; ?>>GGG</option>  <option value="HHH" <?php if($_POST['ApprovedBy'] == 'HHH') echo "selected='selected'"; ?>>HHH</option></select></div><div id='Received_By'><label>Issued By:</label><select name="IssuedBy"><option name='Select'>Select</option><option value="III" <?php if($_POST['ReceivedBy'] == 'III') echo "selected='selected'"; ?>>III</option>  <option value="JJJ" <?php if($_POST['ReceivedBy'] == 'JJJ') echo "selected='selected'"; ?>>JJJ</option> <option value="KKK" <?php if($_POST['ReceivedBy'] == 'KKK') echo "selected='selected'"; ?>>KKK</option>  <option value="LLL" <?php if($_POST['ReceivedBy'] == 'LLL') echo "selected='selected'"; ?>>LLL</option></select></div><div id='Issued_By'><label>Received By:</label><select name="ReceivedBy"><option name='Select'>Select</option><option value="MMM" <?php if($_POST['IssuedBy'] == 'MMM') echo "selected='selected'"; ?>>MMM</option>  <option value="NNN" <?php if($_POST['IssuedBy'] == 'NNN') echo "selected='selected'"; ?>>NNN</option> <option value="OOO" <?php if($_POST['IssuedBy'] == 'OOO') echo "selected='selected'"; ?>>OOO</option>  <option value="PPP" <?php if($_POST['IssuedBy'] == 'PPP') echo "selected='selected'"; ?>>PPP</option></select></div><div id="save_btn"><input type="button" name="button" value="save" onClick="save_sr()" style="width: 5em;"></div></form></body></html>

I will attach my sample form output

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...