Why doesnt this query work?
Posted: Tue Apr 08, 2008 11:29 am
In fact it works but not as it is supposed to be
Here is my code
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 :
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?
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>';
}
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>';
}
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?