Page 1 of 1

Why doesnt this query work?

Posted: Tue Apr 08, 2008 11:29 am
by mrtblt
In fact it works but not as it is supposed to be

Here is my code

Code: Select all

 
      $sql = mysql_query("SELECT c.id,cs.cl_id,ih.client_id,cf.cl_id,c.cl_name, 
      sum(ih.grand_sum*ih.exch_rate*ih.carpan*((100-(ih.disc_prcnt))/100)+cs.miktar*cs.carpan) as bakiye 
      FROM clients as c 
      left join inv_header as ih on c.id=ih.client_id 
      left join ceksenet as cs on c.id=cs.cl_id 
      left join cfis as cf on c.id=cf.cl_id 
      group by c.id order by bakiye ASC ");   
      while($row = mysql_fetch_object($sql))   
      {      
      echo '<br><p><span class="half2"><b>'.$row->cl_name.'</b></span>:'.number_format($row->bakiye,2,",",".").'</p>';
      }   
 
 
 
In this code, as values for $row->cl_name are being listed perfectly, $row->cl_name values appears to be zero or zero values with digits.

If i change the code to the following form :

Code: Select all

 
      $sql = mysql_query("SELECT c.id,cs.cl_id,ih.client_id,cf.cl_id,c.cl_name, 
      sum(ih.grand_sum*ih.exch_rate*ih.carpan*((100-(ih.disc_prcnt))/100)) as bakiye 
      FROM clients as c 
      left join inv_header as ih on c.id=ih.client_id 
      left join ceksenet as cs on c.id=cs.cl_id 
      left join cfis as cf on c.id=cf.cl_id 
      group by c.id order by bakiye ASC ");   
      while($row = mysql_fetch_object($sql))   
      {      
      echo '<br><p><span class="half2"><b>'.$row->cl_name.'</b></span>:'.number_format($row->bakiye,2,",",".").'</p>';
      }   
 
Here i removed cs.miktar*cs.carpan from the sum in the query.
Now all the values are listed without problem except strange ordering of the list by bakiye.
I think the problem is caused by trying adding values in sum. But i need this summation on order to order the table by this value.

S how i may fix thos problem?