Ok let me ask what are you trying to do code wise? Your getting data from the database but not using that data at all in your first post.

Your also using
PHP Code:
include'config.php'
This is the wrong way to do it because include is a built in function you need the (). the correct way is
PHP Code:
include('config.php'); // include back end 
I suggest that you comment your code to so you know what your trying to do and also use a IDE so you have syntax highlighting so you know if your making a mistake in your code.

Code Lobster is a free IDE that is pretty good http://www.codelobster.com/

Also your first script will not work because your missing the last two }}, if you add them it will close off the two starting if statements your using.

Why are you using the SUM aggregate function for in your queries? You use this to get the total of all specified columns(adds the values of all of the together). Only use this if your trying to figure out your total amount earned or something along those lines plus your using the old join method to when your only selection one value you should not use a join either old fashioned or new fashions(declare it as a join)
This query does not make sense to me because its only selecting one value from one table but joins it with another table which has nothing being selected for return

Code:
SELECT SUM(t.input_qty) AS spreading_input FROM clt_traceability AS t, clt_transact AS p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name='Total1' AND p.clt_no = '".$clt_no."'
The above should just be

Code:
SELECT SUM(t.input_qty) AS spreading_input FROM clt_traceability AS t
The reason is that your only selecting this value from this table and no data is selected from the joined table which is a waste of resources because the data is not being used.

If you want to get the total number of rows use the COUNT function instead
Code:
SELECT COUNT(*) FROM clt_transact
Are you trying to get the percentage on this or something?Use a function instead of rewriting the code over and over again.

percentage function excepts additional parameter for rounding and by default rounds
PHP Code:
function percentage($origVal,$newVal,$round="true")
{

$percent = ($newVal $origVal) * 100;

// check if round is false dont round
if($round == "true")
{

return 
round($percent);


}
else
{

return 
$percent;

}


This is the fixed script so that the syntax is correct but I did not adjust the code so that it works because I would like to know what your trying to get done code wise so I can help you get to that point once you tell me what it is your trying to do.

PHP Code:
<?php

/* include is a function so you need to use include('page.php'); and not include'page.php'; */

include('config.php');// include backend for database connection

$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// rows were returned from database
    
{
                    
        
$spreading_input 0;
        
$clicking_output 0;
                    
        
$query  "SELECT SUM(t.input_qty) AS spreading_input FROM clt_traceability AS t, clt_transact AS 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)
            {
                
                
$spreading_input mysql_result($resultyield,0,"spreading_input");
                
            }
        
        }
                    
        
$query  "SELECT SUM(t.output_qty) AS clicking_output FROM clt_traceability AS t, clt_transact AS 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)
            {
                
                
$clicking_output mysql_result($resultyield,0,"clicking_output");
                
            }
         
         }
                          
         
$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;
                        
         }
         
    }
    
}
?>
Post what it is your trying to do so I can help you from there so your code will be cleaner with less lines of code.

Last edited by pein87; 4Jan2011 at 11:01..
shabbir like this