Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Confused in using if condition
Old 12-29-2010, 03:57 AM Confused in using if condition
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Good day!

I have a problem in if and else condition to know if the cloth type is NW (AAA or BBB or CCC) and W the rest cloth type that did not listed in NW. My code did not read the code for NW, only W was read so that even the cloth type is NW the formula was used is the formula of W. I don’t know what is wrong in my code so that if the cloth type is NW the formula is $CLT_yield = @($output / ($input * 8.8)) * 100; and if W the formula is $CLT_yield = @($output / ($input * 9)) * 100;

In my code only the code $CLT_yield = @($output / ($input * 9)) * 100; was run even the cloth type is CCC.

Here is my code:
PHP Code:
<?php
  
<?php
  
<?php
include 'config.php';
if(
$_POST["clt_date"])
        {
        
$query "SELECT clt_no FROM clt_transact WHERE clt_date = '" $_POST["clt_date"] . "'";
        
$result_loop mysql_query($query);
        
        
$date $_POST["clt_date"];
                
        if(
$result_loop) if(mysql_num_rows($result_loop) > 0)
            {
            
$totalloop mysql_num_rows($result_loop);
            
            
$clt_no mysql_result($result_loop,0,"clt_no");
            
$query "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM clt_traceability d, clt_transact t WHERE t.clt_no = '$clt_no' AND d.clt_transact_id = t.clt_transact_id AND d.operation_name IN ('Total1', 'Total2', 'Operation3', 'Operation4', 'Operation5')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> Date: &nbsp;  " $date "</b></tr>";
                echo 
"<th class='tdclass'>CLT #</th>";
                
$total_row mysql_num_rows($result);
                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 />(" mysql_result($result,$ctr,"output_unit") . ")</th>";
                    }
                echo 
"<th class='tdclass'>CLT 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 clt_no FROM clt_transact WHERE clt_date = '" $_POST["clt_date"] . "' ORDER BY clt_no ASC";
        
$result_loop mysql_query($query);               
        while(
$row mysql_fetch_array($result_loop))
            {
            
$loopctr += 1;
            
$clt_no $row["clt_no"];
            
$query "SELECT * FROM clt_transact WHERE clt_no = '$clt_no'";
            
$result_no mysql_query($query);
            if(
$result_no)
                {
                if(
mysql_num_rows($result_no) > 0)
                    {
                    
                    
$input 0;
                    
$output 0;
                    
                    
///Non-W////
                    
                    
$query  "SELECT SUM(t.input_qty) AS input FROM clt_traceability t, clt_transact p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name='Total1' AND p.cloth_type IN ('AAA', 'BBB', 'CCC') AND p.clt_no = '$clt_no'";
                    
$resultyield mysql_query($query);
                    if(
$resultyield)
                        {
                        if(
mysql_num_rows($resultyield) > 0$input mysql_result($resultyield,0,"input");
                        }
                    
                    
$query  "SELECT SUM(t.output_qty) AS output FROM clt_traceability t, clt_transact p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name='Total2' AND p.cloth_type IN ('AAA', 'BBB', 'CCC') AND p.clt_no = '$clt_no'";
                    
$resultyield mysql_query($query);
                    if(
$resultyield)
                        {
                        if(
mysql_num_rows($resultyield) > 0$output mysql_result($resultyield,0,"output");
                        }
                        
                    
$CLT_yield = @($output / ($input 8.8)) * 100;
                    
                    
///W////
                    
                    
$query  "SELECT SUM(t.input_qty) AS input FROM clt_traceability t, clt_transact p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name='Total1' AND p.clt_no = '$clt_no'";
                    
$resultyield mysql_query($query);
                    if(
$resultyield)
                        {
                        if(
mysql_num_rows($resultyield) > 0$input mysql_result($resultyield,0,"input");
                        }
                    
                    
$query  "SELECT SUM(t.output_qty) AS output FROM clt_traceability t, clt_transact p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name='Total2' AND p.clt_no = '$clt_no'";
                    
$resultyield mysql_query($query);
                    if(
$resultyield)
                        {
                        if(
mysql_num_rows($resultyield) > 0$output mysql_result($resultyield,0,"output");
                        }
                        
                    
$CLT_yield = @($output / ($input 9)) * 100;
                     
                   
$query "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM clt_traceability d, clt_transact t WHERE t.clt_no = '$clt_no' AND d.clt_transact_id = t.clt_transact_id AND d.operation_name IN ('Total1', 'Total2', 'Operation3', 'Operation4', 'Operation5') GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name";
                    
$result mysql_query($query);
                    if(
$result)
                        {
                       
                        
                        echo 
"<tr>";
                        echo 
"<td><strong>$clt_no</strong></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>";
                          } 
                            
                        echo 
"<td class='tdclass'><strong>";
                        
printf ("%01.2f"$CLT_yield);
                         echo 
"%</strong></td>";
                     
                        echo 
"</tr>";
                        
                    
                        }
                    }
                }
            }
            echo 
"</table>";              
            }
?>


I hope somebody can help me.

Any help is highly appreciated.

Thank you
newphpcoder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-02-2011, 09:16 AM Re: Confused in using if condition
Junior Talker

Posts: 1
Trades: 0
Hello,

Well, your if statement should follow this method:



PHP Code:
$my_type 'NW'

if(
$my_type == 'NW')
{
    
$CLT_yield = @($output / ($input 9)) * 100;
}
elseif(
$my_type == 'NON-NW')
{
    
$CLT_yield = @($output / ($input 8.8)) * 100;

Hope that helps a bit
__________________
CYTechnologies - Happy Coding!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
cytech is offline
Reply With Quote
View Public Profile
 
Old 01-03-2011, 01:11 AM Re: Confused in using if condition
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
I try new code like this:

PHP Code:
$query "SELECT cloth_type FROM clt_transact WHERE cloth_type IN('AAA', 'BBB', 'CCC')";
                      
$result mysql_query($query);
                      
//$cloth_type = $result['cloth_type'];
                      
if($result){
                            
$CLT_yield = @($clicking_output / ($spreading_input 8.8)) * 100;
                                 }
                      else{
                            
$CLT_yield = @($clicking_output / ($spreading_input 9)) * 100;
                          } 
To test if the two formula was work i have data that the cloth type is AAA and I have data that the cloth type is DDD and when I run my code only the first formula was work even the cloth type is DDD. I don't know why the else condition did not work in cloth type DDD.why the formula in AAA was work in the DDD cloth type. I mean only this formula:$CLT_yield = @($clicking_output / ($spreading_input * 8.8)) * 100; was work in both AAA and DDD.

Thank you
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 01-03-2011, 07:46 AM Re: Confused in using if condition
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
To address your last two bits of code: mysql_query for a SELECT returns a resource, in this case an array of values. if $result will always be the branch executed if you have any matching rows. The query itself doesn't make sense -- select x if record contains x.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-03-2011, 07:24 PM Re: Confused in using if condition
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
What should i do in my code to work my code. I have new code in my new code only the if condition was work even the cltoh type is DDD.
here is my new code:
PHP Code:
  
                       $query  
"SELECT cloth_type FROM clt_transact WHERE cloth_type IN ('AAA', 'BBB', 'CCC')";
                       
$record mysql_query($query);
                       
$result mysql_fetch_assoc($record);
                       
$cloth_type $result['cloth_type']; 
                       if (
$cloth_type == 'AAA' || $cloth_type == 'BBB' || $cloth_type == 'CCC') {
                        
$CLT_yield = @($clicking_output / ($spreading_input 8.8)) * 100;
                        }     
                       else {
                        
$CLT_yield = @($clicking_output / ($spreading_input 9)) * 100;
                        } 
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 01-03-2011, 07:44 PM Re: Confused in using if condition
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by PaulW View Post
The query itself doesn't make sense -- select x if record contains x.
Take a step back, break the problem down into smalller components. Address each component one at a time, don't just leap in and change things blindly hoping something will work.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Confused in using if condition
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.55576 seconds with 12 queries