newphpcoder Posted April 24, 2012 Share Posted April 24, 2012 Hi.. I have a function for convert to dozen. here 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); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Job Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <div id="ddcolortabs"> <ul> <li id="current"> <a href="SalesOrder.php" title="Sales Order"><span>Order Management</span></a></li> <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><a href="fsn.php" title="Finished Stock Note"><span>WMS FG</span></a></li> <li><a href="ReceivingMaterials.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="SalesOrder.php" title="Sales Order"><span>Sales Order</span></a></li> <li id="current"><a href="JobOrder.php" title="Job Order"><span>Job Order</span></a></li> </ul> </div> <div id="SR_date"> <input type="hidden" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <?php //----approve button-----// $Approved = isset($_POST['priority']); if ($Approved) { $PO_No = $_POST['PO_No']; $ETD = $_POST['ETD']; $SKUCode = $_POST['SKUCode']; $Description = $_POST['Description']; $POReq = $_POST['POReq']; $priority = $_POST['priority']; $sql = "SELECT SKUCode, Materials, Comp, Qty FROM bom WHERE SKUCode = '$SKUCode'"; $res = mysql_query($sql, $con); $row = mysql_fetch_assoc($res); $Materials = $row['Materials']; $Qty = $row['Qty']; $Comp = $row['Comp']; $ReqQty = $Qty * $POReq; $sql = "UPDATE bom SET ReqQty = '$ReqQty' WHERE SKUCode = '$SKUCode' AND Materials = '$Materials'"; $resReqQty = mysql_query($sql, $con); $sql = "SELECT SUM(WEIGHING) AS WEIGHING_TOTAL, "; $sql .= "SUM(COMPOUNDING) AS COMPOUNDING_TOTAL, "; $sql .= "SUM(EXTRUSION) AS EXTRUSION_TOTAL, "; $sql .= "SUM(FORMING) AS FORMING_TOTAL, "; $sql .= "SUM(DIPPING) AS DIPPING_TOTAL, "; $sql .= "SUM(MOULDING) AS MOULDING_TOTAL "; $sql .= "FROM MES_REPORT_OPEN WHERE SUBSTRING(LOT_CODE, 9) = '$Comp'"; $result = mysql_query($sql, $con); $weighingTotal = mysql_result($result, 0, "WEIGHING_TOTAL"); $weighingTotal = convertToDozen($weighingTotal, $Comp); $weighingAccum = $weighingAccum + $weighingTotal; $compoundingTotal = mysql_result($result, 0, "COMPOUNDING_TOTAL"); $compoundingTotal = convertToDozen($compoundingTotal, $Comp); $compoundingAccum = $compoundingAccum + $compoundingTotal; $extrusionTotal = mysql_result($result, 0, "EXTRUSION_TOTAL"); $extrusionTotal = convertToDozen($extrusionTotal, $Comp); $extrusionAccum = $extrusionAccum + $extrusionTotal; $formingTotal = mysql_result($result, 0, "FORMING_TOTAL"); $formingTotal = convertToDozen($formingTotal, $Comp); $formingAccum = $formingAccum = $formingTotal; $dippingTotal = mysql_result($result, 0, "DIPPING_TOTAL"); $dippingTotal = convertToDozen($dippingTotal, $Comp); $dippingAccum = $dippingAccum + $dippingTotal; $virtualY = $weighingTotal + $compoundingTotal + $extrusionTotal + $formingTotal; $totalY = $dippingTotal + $virtualY; function convertToDozen ($total, $cmpdType) { switch ($cmpdType) { case "P28" : $convTotal = (($total * 1000) / 22.00) / 12; break; case "P30" : $convTotal = (($total * 1000) / 25.10) / 12; break; case "P32" : $convTotal = (($total * 1000) / 22.50) / 12; break; case "P33" : $convTotal = (($total * 1000) / 25.00) / 12; break; case "P35" : $convTotal = (($total * 1000) / 25.25) / 12; break; case "P35M" : $convTotal = (($total * 1000) / 22.60) / 12; break; case "P35W" : $convTotal = (($total * 1000) / 22.50) / 12; break; case "P38" : $convTotal = (($total * 1000) / 26.70) / 12; break; case "P41" : $convTotal = (($total * 1000) / 24.80) / 12; break; case "P42" : $convTotal = (($total * 1000) / 18.90) / 12; break; case "P43" : $convTotal = (($total * 1000) / 25.00) / 12; break; case "P46" : $convTotal = (($total * 1000) / 27.00) / 12; break; case "P47" : $convTotal = (($total * 1000) / 27.60) / 12; break; } return round($convTotal, 2); } } else{ } $sql = "SELECT jo_number, ETD, PO_No, SKUCode, Description, POQty, Priority FROM job_order ORDER BY jo_number, ETD"; $res = mysql_query($sql,$con); ?> <div id="kanban_table" style="overflow:auto; height:215px;"> <table> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Priority</th> <?php $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order WHERE NOT EXISTS (SELECT PO_No FROM job_order WHERE job_order.PO_No = sales_order.PO_No) ORDER BY ETD, PO_No "; $res_so = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_so)){ echo "<form name='joborder_form' action='' method='post'>"; $PO_No = $row['PO_No']; echo "<tr> <td><input type='text' value='' style='border:none;' size='10'></td> <td><input type='text' name='ETD' id='ETD' value='$row[ETD]' style='border:none;' size='10'></td> <td><input type='text' name='PO_No' id='PO_No' value='$row[PO_No]' style='border:none;' size='30'></td> <td><input type='text' name='SKUCode' id='SKUCode' value='$row[sKUCode]' style='border:none;' size='15'></td> <td><input type='text' name='Description' id='Description' value='$row[Description]' style='border:none;' size='35'></td> <td><input type='text' name='POReq' id='POReq' value='$row[POReq]' style='border:none;' size='10'></td> <td><input type='submit' name='priority' value='Approved' id='priority'></td> </tr>"; echo "</form>"; } echo "</table>"; echo "</div>"; echo "<div style='overflow:auto; height:215px;'>"; echo "<table>"; while($row_job = mysql_fetch_assoc($res)){ echo "<tr> <td><input type='text' name='JO_No_' id='JO_No_' value='$row_job[jo_number]' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='ETD_' id='ETD_' value='$row_job[ETD]' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='PO_No_' id='PO_No_' value='$row_job[PO_No]' style='border:none;' size='30'></td> <td><input type='text' name='SKUCode_' id='SKUCode_' value='$row_job[sKUCode]' style='border:none;' size='15'></td> <td><input type='text' name='Description_' id='Description_' value='$row_job[Description]' style='border:none;' size='35'></td> <td><input type='text' name='POReq_' id='POReq_' value='$row_job[POQty]' style='border:none;width:auto;' size='10'></td> <td><input type='text' name='priority_' value='$row_job[Priority]' id='priority_' style='border:none;width:auto;' size='10'></td> </tr>" ; } echo "</table>"; echo "</div>" ?> </body> </html> but I when I echo this: echo $weighingTotal; No result, then when I debug my code I got an error: Call to undefined function. I can’t configured out where in my code was wrong? Any help is highly appreciated. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/261558-error-call-to-undefined-function/ Share on other sites More sharing options...
teynon Posted April 24, 2012 Share Posted April 24, 2012 The error "Call to undefined function" means you did not define the function. Which means you didn't include it in the file. include "path_to_function_file.php"; Quote Link to comment https://forums.phpfreaks.com/topic/261558-error-call-to-undefined-function/#findComment-1340283 Share on other sites More sharing options...
trq Posted April 24, 2012 Share Posted April 24, 2012 Your code is all over the place. Your function is declared within an if statement, meaning it will only exists if $Approved is true. You also do most of your displaying logic outside of this if statement without ever checking to see if your query actually succeeds before using it's result. It needs a rewrite. Quote Link to comment https://forums.phpfreaks.com/topic/261558-error-call-to-undefined-function/#findComment-1340284 Share on other sites More sharing options...
newphpcoder Posted April 25, 2012 Author Share Posted April 25, 2012 You mean I will put my function inside my if condition? Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/261558-error-call-to-undefined-function/#findComment-1340290 Share on other sites More sharing options...
creata.physics Posted April 25, 2012 Share Posted April 25, 2012 No, put the function outside your if statement. preferably at the top of your page. Quote Link to comment https://forums.phpfreaks.com/topic/261558-error-call-to-undefined-function/#findComment-1340295 Share on other sites More sharing options...
newphpcoder Posted April 25, 2012 Author Share Posted April 25, 2012 Thank you. I tried it and it works now Quote Link to comment https://forums.phpfreaks.com/topic/261558-error-call-to-undefined-function/#findComment-1340305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.