Question about if condition
01-27-2011, 07:23 PM
|
Question about if condition
|
Posts: 97
Name: rhoda
|
Good day!
I have if condition in my code and it is for checking the input data from the user or client.
Here is my if statement:
PHP Code:
if($_POST["from1_date"] && $_POST["to1_date"] && $_POST["shift1"])
this code is work when i insert in the text field the from date, to date and the shift. I have 3 types of shift. For example I input from 2011-01-01 to 2011-01-02 shift 1-6 all the data that the shift is 1-6 is appear. My problem now is when i did not input shift no data was appear. I want to happen is when I did not input shift all the data from date to date will appear.
Any help is highly appreciated.
Thank you
|
|
|
|
01-27-2011, 08:56 PM
|
Re: Question about if condition
|
Posts: 879
Name: Paul W
|
if($_POST["from1_date"] && $_POST["to1_date"] {if $_POST["shift1"]) {do one thing} else {do another thing}}
|
|
|
|
01-30-2011, 02:05 PM
|
Re: Question about if condition
|
Posts: 23
|
In this if condition you are validating that all the fields must be filled. If you don't want to consider shift, then simply remove it from the if condition (and from the database query as well if it is there too).
|
|
|
|
01-30-2011, 08:09 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
Quote:
Originally Posted by mwasif
In this if condition you are validating that all the fields must be filled. If you don't want to consider shift, then simply remove it from the if condition (and from the database query as well if it is there too).
|
Sorry to say but I could not remove the shift in my if condition. I only want is even the user did not input shift the output should be depend on from date and to date..
Thank you
|
|
|
|
01-30-2011, 08:26 PM
|
Re: Question about if condition
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
What does the shift mean?
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
01-30-2011, 08:36 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
Quote:
Originally Posted by mgraphic
What does the shift mean?
|
shift means the shift of operators like 6-6 10-6
|
|
|
|
01-30-2011, 08:54 PM
|
Re: Question about if condition
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
Why not use:
if($_POST["from1_date"] && $_POST["to1_date"])
And use shift if ($_POST["shift1"] > 0)
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
01-30-2011, 09:29 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
Good day!
I tried again the code that you given to me.
like this:
PHP Code:
elseif($_POST["from1_date"] && $_POST["to1_date"]) { if($_POST["shift1"] > 0) $from_date = mysql_real_escape_string($_POST['from1_date']); $to_date = mysql_real_escape_string($_POST['to1_date']); $shift = mysql_real_escape_string($_POST['shift1']); ///and the rest of code }
in this code, as you can see the if condition for shift has no and when i insert from date and to date and the shift is blank the output of this code is the last 5 operation name was appear but the input , output, and yield was zero
and when i add no output was display
Thank you
|
|
|
|
01-30-2011, 09:32 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
For better understanding here is my whole codes :
PHP Code:
if($_POST["from_date"] && $_POST["to_date"]) { if($_POST["shift1"] > 0) $from_date = mysql_real_escape_string($_POST['from_date']); $to_date = mysql_real_escape_string($_POST['to_date']); $shift = mysql_real_escape_string($_POST['shift']); $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '$from_date' AND '$to_date' AND d.shift = '$shift' AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name"; $result = mysql_query($query); if($result) { echo "<table cellspacing='2' style='font-family: arial narrow; font-size: 12px; border-width: 2px 2px 2px 2px; border-style: solid;'>"; echo "<tr>"; echo "<tr><b> From Date: " . $_POST['from_date'] . "</b></tr>"; echo "<tr><b> To Date: " . $_POST['to_date'] . "</b></tr>"; echo "<tr><b> Shift Date: " . $_POST['shift'] . "</b></tr>"; echo "<th class='tdclass'>PLT #</th>"; $total_row = mysql_num_rows($result); $total_columns = $total_row; for($ctr=0; $ctr < $total_row; $ctr++) { $opname = mysql_result($result,$ctr,"operation_name"); $i = strpos($opname," ",0); $opname = substr($opname,$i); echo "<th colspan='2' class='tdclass'>" . $opname . "<br /></th>"; } echo "<th class='tdclass'>PLT Yield</th>"; echo "</tr>"; echo "<tr>"; echo "<td class='tdclass'></td>"; for($ctr=0; $ctr < $total_row; $ctr++) { echo "<td class='tdclass'>Input</td>"; echo "<td class='tdclass'>Output</td>"; } echo "<td class='tdclass'>"; echo "</td>"; echo "</tr>"; } $query = "SELECT DISTINCT p.plt_no FROM plt_transact p , traceability t WHERE p.plt_date BETWEEN '" . $_POST["from_date"] . "' AND '" . $_POST["to_date"] . "' AND t.shift = '". $_POST["shift"] ."' AND t.operation_name IN('01 Oper' , '02 Oper' , '03 Oper' , '04 Oper') AND p.plt_transact_id = t.plt_transact_id "; $result_loop = mysql_query($query); while($row = mysql_fetch_array($result_loop)) { $loopctr += 1; $plt_no = $row["plt_no"]; $query = "SELECT * FROM plt_transact WHERE plt_no = '$plt_no'"; $result_no = mysql_query($query); if($result_no) { if(mysql_num_rows($result_no) > 0) { $chemicalweighing_input = 0; $extrusion_output = 0; $query = "SELECT SUM(t.input_qty) AS chemicalweighing_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='01 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $chemicalweighing_input = mysql_result($resultyield,0,"chemicalweighing_input"); } $query = "SELECT SUM(t.output_qty) AS extrusion_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='04 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $extrusion_output = mysql_result($resultyield,0,"extrusion_output"); } $PLT_yield = @($extrusion_output / $chemicalweighing_input) * 100; $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, SUM(d.output_qty) AS outputqty FROM traceability d, plt_transact t WHERE t.plt_no = '$plt_no' AND t.plt_date BETWEEN '$from_date' AND '$to_date' AND d.shift = '$shift' AND d.plt_transact_id = t.plt_transact_id AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper' , '04 Oper') GROUP BY d.operation_name ORDER BY d.operation_name"; $result = mysql_query($query); $total_row = mysql_num_rows($result); if($result) { echo "<tr>"; echo "<td><strong>$plt_no</strong></td>"; if($total_row == 0) { echo "<td class='tdclass'>"; echo "</td>"; echo "<td class='tdclass'>"; echo "</td>"; } for($ctr=0; $ctr < $total_row; $ctr++) { echo "<td class='tdclass'>"; echo number_format((mysql_result($result,$ctr,"inputqty")),2); echo "</td>"; echo "<td class='tdclass'>"; echo number_format((mysql_result($result,$ctr,"outputqty")),2); echo "</td>"; } if($total_row < $total_columns) { for($ctr = 0; $ctr < ($total_columns - $total_row); $ctr++) { echo "<td class='tdclass'>"; echo "</td>"; echo "<td class='tdclass'>"; echo "</td>"; } } echo "<td class='tdclass'><strong>"; printf ("%01.2f", $PLT_yield); echo "%</strong></td>"; echo "</tr>"; } } } } echo "</table>"; }
|
|
|
|
01-30-2011, 09:50 PM
|
Re: Question about if condition
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
You could modifiy your query in the sql:
PHP Code:
if ($_POST["from_date"] && $_POST["to_date"]) { $result = mysql_query(" SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '" . mysql_real_escape_string($_POST['from_date']) . "' AND '" . mysql_real_escape_string($_POST['to_date']) . "' AND " . ((int)$_POST['shift'] > 0 ? "d.shift = " . (int)$_POST['shift'] : "1") . " AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name "); // Rest of code here...
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
01-30-2011, 10:25 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
I tried the code that you suggested like this:
PHP Code:
elseif($_POST["from1_date"] && $_POST["to1_date"]) {
if($_POST["shift1"] > 0)
$from_date = mysql_real_escape_string($_POST['from1_date']); $to_date = mysql_real_escape_string($_POST['to1_date']); $shift = mysql_real_escape_string($_POST['shift1']); $query = " SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '" . mysql_real_escape_string($_POST['from_date']) . "' AND '" . mysql_real_escape_string($_POST['to_date']) . "' AND " . ((int)$_POST['shift'] > 0 ? "d.shift = " . (int)$_POST['shift'] : "1") . " AND d.operation_name IN ('01 Oper, '02 Oper', '03 Oper', '04 Oper' , '05 Oper' , '06 Oper' , '07 Oper', '08 Oper' , '09 Oper' , '10 Oper') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name";
When I run this code the operation name did not appear again and the input ,output, and yield was zero. AND even i input shift the operation name did not appear
|
|
|
|
01-30-2011, 10:39 PM
|
Re: Question about if condition
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
You should drop this part:
PHP Code:
if($_POST["shift1"] > 0)
$from_date = mysql_real_escape_string($_POST['from1_date']); $to_date = mysql_real_escape_string($_POST['to1_date']); $shift = mysql_real_escape_string($_POST['shift1']);
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
01-30-2011, 10:41 PM
|
Re: Question about if condition
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
And I had the post keys named wrong:
PHP Code:
$result = mysql_query(" SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '" . mysql_real_escape_string($_POST['from1_date']) . "' AND '" . mysql_real_escape_string($_POST['to1_date']) . "' AND " . ((int)$_POST['shift1'] > 0 ? "d.shift = " . (int)$_POST['shift1'] : "1") . " AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name ");
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
01-30-2011, 10:42 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
I revised again the codes:
PHP Code:
elseif($_POST["from1_date"] && $_POST["to1_date"]) { if($_POST["shift1"] > 0) $from_date = mysql_real_escape_string($_POST['from1_date']); $to_date = mysql_real_escape_string($_POST['to1_date']); $shift = mysql_real_escape_string($_POST['shift1']); $query = " SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '" . mysql_real_escape_string($_POST['from1_date']) . "' AND '" . mysql_real_escape_string($_POST['to1_date']) . "' AND " . ((int)$_POST['shift1'] > 0 ? "d.shift = " . (int)$_POST['shift1'] : "1") . " AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper' , '05 Oper' , '06 Oper' , '07 Oper', '08 Oper' , '09 Oper' , '10 Oper') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name";
When I try this all the operation name display the only problem now is the input , output, and yield data become zero.
Last edited by newphpcoder; 01-30-2011 at 10:51 PM..
|
|
|
|
01-30-2011, 10:53 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
I delete the code that you suggested to remove:
here is the code:
PHP Code:
elseif($_POST["from1_date"] && $_POST["to1_date"]) { if($_POST["shift1"] > 0) $query = " SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '" . mysql_real_escape_string($_POST['from1_date']) . "' AND '" . mysql_real_escape_string($_POST['to1_date']) . "' AND " . ((int)$_POST['shift1'] > 0 ? "d.shift = " . (int)$_POST['shift1'] : "1") . " AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper' , '05 Oper' , '06 Oper' , '07 Oper', '08 Oper' , '09 Oper' , '10 Oper') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name";
In this code the input, output, yield per operation name was blank before it become zero now totally no output or display. even I insert from date, to date and shift.
Thank you for helping me...
|
|
|
|
02-01-2011, 07:27 PM
|
Re: Question about if condition
|
Posts: 97
Name: rhoda
|
Good day!
Thank you for the suggested logic and code. By the way here is my whole code:
PHP Code:
<?php elseif($_POST["from1_date"] && $_POST["to1_date"] && $_POST["shift1"]) { $from_date = mysql_real_escape_string($_POST['from1_date']); $to_date = mysql_real_escape_string($_POST['to1_date']); $shift = mysql_real_escape_string($_POST['shift1']); $Batch_yield = 0; $c_input = 0; $co_output = 0; $loopctr = 0; $totalloop = 0; $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, SUM(d.output_qty) AS outputqty FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '$from_date' AND '$to_date' AND d.shift = '$shift' AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper' , '05 Oper' , '06 Oper' , '07 Oper', '08 Oper' , '09 Oper' , '10 Oper') GROUP BY d.operation_name ORDER BY d.operation_name"; $result = mysql_query($query); if($result) { echo "<table cellspacing='2' style='font-family: arial narrow; font-size: 12px; border-width: 2px 2px 2px 2px; border-style: solid;'>"; echo "<tr>"; echo "<tr><b> From Date: " . $_POST['from1_date'] . "</b></tr>"; echo "<tr><b> To Date: " . $_POST['to1_date'] . "</b></tr>"; echo "<tr><b> Shift Date: " . $_POST['shift1'] . "</b></tr>"; echo "<th class='tdclass'>PLT #</th>"; $total_row = mysql_num_rows($result); $total_columns = $total_row; for($ctr=0; $ctr < $total_row; $ctr++) { $opname = mysql_result($result,$ctr,"operation_name"); $i = strpos($opname," ",0); $opname = substr($opname,$i); echo "<th colspan='3' class='tdclass'>" . $opname . "<br /></th>"; } echo "<th class='tdclass'>Batch Yield</th>"; echo "</tr>"; echo "<tr>"; echo "<td class='tdclass'></td>"; for($ctr=0; $ctr < $total_row; $ctr++) { echo "<td class='tdclass'>Input</td>"; echo "<td class='tdclass'>Output</td>"; echo "<td class='tdclass'>Yield</td>"; } echo "<td class='tdclass'>"; echo "</td>"; echo "</tr>"; } $query = "SELECT DISTINCT p.plt_no FROM plt_transact p, traceability t WHERE plt_date BETWEEN '" . $_POST["from1_date"] . "' AND '" . $_POST["to1_date"] . "' AND t.shift = '" . $_POST["shift1"] . "' AND p.plt_transact_id = t.plt_transact_id"; $result_loop = mysql_query($query); while($row = mysql_fetch_array($result_loop)) { $loopctr += 1; $plt_no = $row["plt_no"]; $query = "SELECT * FROM plt_transact WHERE plt_no = '$plt_no'"; $result_no = mysql_query($query); if($result_no) { if(mysql_num_rows($result_no) > 0) { $chemical_input = 0; $core_output = 0; $query = "SELECT SUM(t.output_qty) AS c_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='01 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $c_input = $c_input + mysql_result($resultyield,0,"c_input"); } $query = "SELECT SUM(t.output_qty) AS co_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='10 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $co_output = $co_output + mysql_result($resultyield,0,"co_output"); } $PLT_yield = @($co_output / $c_input) * 100; $query = "SELECT SUM(t.input_qty) AS c_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='01 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $c_input = $chem_input + mysql_result($resultyield,0,"c_input"); } $query = "SELECT SUM(t.output_qty) AS co_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='10 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $co_output = $co_output + mysql_result($resultyield,0,"co_output"); } $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, SUM(d.output_qty) AS outputqty FROM traceability d, plt_transact t WHERE t.plt_no = '$plt_no' AND t.plt_date BETWEEN '$from_date' AND '$to_date' AND d.shift = '$shift' AND d.plt_transact_id = t.plt_transact_id GROUP BY d.operation_name ORDER BY d.operation_name"; $result = mysql_query($query); if($result) { echo "<tr>"; echo "<td><strong>$plt_no</strong></td>"; while($row2 = mysql_fetch_array($result)) { echo "<td class='tdclass'>" . number_format($row2["inputqty"],2) . "</td>"; echo "<td class='tdclass'>" . number_format($row2["outputqty"],2) . "</td>"; $inputqty = $row2["inputqty"]; $outputqty = $row2["outputqty"]; $yield = @(($outputqty / $inputqty)*100); echo "<td class='tdclass'>" . number_format($yield,2) . "</td>"; echo "</td>"; } echo "<td style='text-align: right; font-weight: bold; font-family: Arial; font-size:10' class = 'tdclass' colspan='"; $loopctr = ($total_row * 2) + 20; echo "$loopctr'>"; printf ("%01.2f", $PLT_yield); echo "<strong>%"; echo "</td>"; echo "</tr>"; } } } } $Batch_yield = @($coresolutioning_output / $chem_input) * 100; echo "<tr>"; echo "<td style='text-align: right; font-weight: bold; font-family: Arial; font-size:10' class = 'tdclass' colspan='"; $loopctr = ($total_row * 2) + 20; echo "$loopctr'>Total Batch Yield: "; printf ("%01.2f", $Batch_yield); echo "<strong>%"; echo "</td>"; echo "</tr>"; echo "</table>"; } ?>
Where I don't know how can i used the codes that you suggested.
Thank you
In that code if i input from date, to date and shift the output display is correct the elseif condition was satisfied, but when i only input from date and to date no output display and I want to be output is all the data in the database where the date os from date and to date.
Thank you
|
|
|
|
02-01-2011, 09:21 PM
|
Re: Question about if condition
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
PHP Code:
<?php elseif($_POST["from1_date"] && $_POST["to1_date"]) { $from_date = mysql_real_escape_string($_POST['from1_date']); $to_date = mysql_real_escape_string($_POST['to1_date']); $shift = mysql_real_escape_string($_POST['shift1']); $Batch_yield = 0; $c_input = 0; $co_output = 0; $loopctr = 0; $totalloop = 0; $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, SUM(d.output_qty) AS outputqty FROM traceability d, plt_transact t WHERE t.plt_date BETWEEN '$from_date' AND '$to_date' AND " . ((int)$shift > 0 ? "d.shift = " . (int)$shift : "1") . " AND d.operation_name IN ('01 Oper', '02 Oper', '03 Oper', '04 Oper' , '05 Oper' , '06 Oper' , '07 Oper', '08 Oper' , '09 Oper' , '10 Oper') GROUP BY d.operation_name ORDER BY d.operation_name"; $result = mysql_query($query); if($result) { echo "<table cellspacing='2' style='font-family: arial narrow; font-size: 12px; border-width: 2px 2px 2px 2px; border-style: solid;'>"; echo "<tr>"; echo "<tr><b> From Date: " . $_POST['from1_date'] . "</b></tr>"; echo "<tr><b> To Date: " . $_POST['to1_date'] . "</b></tr>"; echo "<tr><b> Shift Date: " . $_POST['shift1'] . "</b></tr>"; echo "<th class='tdclass'>PLT #</th>"; $total_row = mysql_num_rows($result); $total_columns = $total_row; for($ctr=0; $ctr < $total_row; $ctr++) { $opname = mysql_result($result,$ctr,"operation_name"); $i = strpos($opname," ",0); $opname = substr($opname,$i); echo "<th colspan='3' class='tdclass'>" . $opname . "<br /></th>"; } echo "<th class='tdclass'>Batch Yield</th>"; echo "</tr>"; echo "<tr>"; echo "<td class='tdclass'></td>"; for($ctr=0; $ctr < $total_row; $ctr++) { echo "<td class='tdclass'>Input</td>"; echo "<td class='tdclass'>Output</td>"; echo "<td class='tdclass'>Yield</td>"; } echo "<td class='tdclass'>"; echo "</td>"; echo "</tr>"; } $query = "SELECT DISTINCT p.plt_no FROM plt_transact p, traceability t WHERE plt_date BETWEEN '" . $_POST["from1_date"] . "' AND '" . $_POST["to1_date"] . "' AND t.shift = '" . $_POST["shift1"] . "' AND p.plt_transact_id = t.plt_transact_id"; $result_loop = mysql_query($query); while($row = mysql_fetch_array($result_loop)) { $loopctr += 1; $plt_no = $row["plt_no"]; $query = "SELECT * FROM plt_transact WHERE plt_no = '$plt_no'"; $result_no = mysql_query($query); if($result_no) { if(mysql_num_rows($result_no) > 0) { $chemical_input = 0; $core_output = 0; $query = "SELECT SUM(t.output_qty) AS c_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='01 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $c_input = $c_input + mysql_result($resultyield,0,"c_input"); } $query = "SELECT SUM(t.output_qty) AS co_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='10 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $co_output = $co_output + mysql_result($resultyield,0,"co_output"); } $PLT_yield = @($co_output / $c_input) * 100; $query = "SELECT SUM(t.input_qty) AS c_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='01 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $c_input = $chem_input + mysql_result($resultyield,0,"c_input"); } $query = "SELECT SUM(t.output_qty) AS co_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='10 Oper' AND p.plt_no = '$plt_no'"; $resultyield = mysql_query($query); if($resultyield) { if(mysql_num_rows($resultyield) > 0) $co_output = $co_output + mysql_result($resultyield,0,"co_output"); } $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, SUM(d.output_qty) AS outputqty FROM traceability d, plt_transact t WHERE t.plt_no = '$plt_no' AND t.plt_date BETWEEN '$from_date' AND '$to_date' AND d.shift = '$shift' AND d.plt_transact_id = t.plt_transact_id GROUP BY d.operation_name ORDER BY d.operation_name"; $result = mysql_query($query); if($result) { echo "<tr>"; echo "<td><strong>$plt_no</strong></td>"; while($row2 = mysql_fetch_array($result)) { echo "<td class='tdclass'>" . number_format($row2["inputqty"],2) . "</td>"; echo "<td class='tdclass'>" . number_format($row2["outputqty"],2) . "</td>"; $inputqty = $row2["inputqty"]; $outputqty = $row2["outputqty"]; $yield = @(($outputqty / $inputqty)*100); echo "<td class='tdclass'>" . number_format($yield,2) . "</td>"; echo "</td>"; } echo "<td style='text-align: right; font-weight: bold; font-family: Arial; font-size:10' class = 'tdclass' colspan='"; $loopctr = ($total_row * 2) + 20; echo "$loopctr'>"; printf ("%01.2f", $PLT_yield); echo "<strong>%"; echo "</td>"; echo "</tr>"; } } } } $Batch_yield = @($coresolutioning_output / $chem_input) * 100; echo "<tr>"; echo "<td style='text-align: right; font-weight: bold; font-family: Arial; font-size:10' class = 'tdclass' colspan='"; $loopctr = ($total_row * 2) + 20; echo "$loopctr'>Total Batch Yield: "; printf ("%01.2f", $Batch_yield); echo "<strong>%"; echo "</td>"; echo "</tr>"; echo "</table>"; } ?>
Last edited by mgraphic; 02-01-2011 at 09:22 PM..
|
|
|
|
|
« Reply to Question about if condition
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|