将值与其他值的总和一起列出一次
Listing values once with their sum of other values
正如您在图片中看到的,我使用这些代码列出来自 mysql 数据库的产品:
$satis_cek = mysql_query("SELECT * FROM satislar WHERE zno = '".$zno."'");
$varmi = mysql_num_rows($satis_cek);
$toplam_tutar = 0;
$indirim = 0;
$genel_toplam = 0;
if($varmi == ""){
$ara_toplam = 0;
$indirim_toplam = 0;
$genel_toplamlar= 0;
}else{
while ($satis_al = mysql_fetch_array($satis_cek)){
$sat_fatura_no = $satis_al['sat_fatura_no'];
$personel = $satis_al['sat_uye_id'];
$sat_tarih = $satis_al['sat_tarih'];
$sat_tip = $satis_al['sat_tip'];
$toplam_tutar += $satis_al['toplam_tutar'];
$indirim += $satis_al['indirim'];
$genel_toplam += $satis_al['genel_toplam'];
$fis_cek = mysql_query("SELECT * FROM stok_hareketleri WHERE sth_fatura_no = '".$sat_fatura_no."'");
while ($a= mysql_fetch_array($fis_cek)){
$sth_stok_kodu = $a['sth_stok_kod'];
$sth_adet = $a['sth_adet'];
$sth_tutar = $a['sth_tutar'];
$stok_cek = mysql_query("SELECT * FROM stoklar WHERE sto_RECno = '".$sth_stok_kodu."'");
while ($stok_al = mysql_fetch_array($stok_cek)){
$sto_isim = $stok_al['sto_isim'];
echo'
<tr>
<td align="left">'.$sto_isim.'</a></td>
<td align="center">'.$sth_adet.'</td>
<td align="right">'.$sth_tutar.'</td>
</tr>';}}}}
如图所示,我尝试列出一次 Jack Daniel's 并计算其销售数量和销售价格的总和,并将它们打印在 html table 行。
例如:
Jack Daniel's 2 220.00
Yeni Rakı 70 cl 1 85.00
Fanta 330 ml 1 3.00
我是 php 的新手,所以我无法解决如何使用相同 mysql table 的销售数量总和和价格总和来显示每个产品一次的问题。
这样尝试:table1
是产品详情 table,table2
是已售商品 table。
select sto_isim,sum(sth_tutar) as sum,sum(sth_adet) as cnt from table1 join table2 on table1.sto_RECno=table2.sth_stok_kod group by sto_RECno
这应该为每个产品提供单行以及总和和计数。
$tarih2 = date("Y-m-d 00:00:00",strtotime($_POST['tarih']));
$tarih3 = date("Y-m-d 23:59:59",strtotime($_POST['tarih']));
$satis_cek = mysql_query("SELECT * FROM satislar WHERE zno = '".$zno."'");
$varmi = mysql_num_rows($satis_cek);
$toplam_tutar = 0;
$indirim = 0;
$genel_toplam = 0;
if($varmi == ""){
$ara_toplam = 0;
$indirim_toplam = 0;
$genel_toplamlar= 0;
}else{
while ($satis_al = mysql_fetch_array($satis_cek)){
$sat_fatura_no = $satis_al['sat_fatura_no'];
$personel = $satis_al['sat_uye_id'];
$sat_tarih = $satis_al['sat_tarih'];
$sat_tip = $satis_al['sat_tip'];
$toplam_tutar += $satis_al['toplam_tutar'];
$indirim += $satis_al['indirim'];
$genel_toplam += $satis_al['genel_toplam'];}
$fis_cek = mysql_query("select sto_isim,sum(sth_tutar) as sum,sum(sth_adet) as cnt from stoklar join stok_hareketleri on stoklar.sto_RECno=stok_hareketleri.sth_stok_kod WHERE stok_hareketleri.sth_create_date >= '".$tarih2."' AND stok_hareketleri.sth_create_date <= '".$tarih3."' AND sth_tip = 'Satış Fişi' group by stoklar.sto_RECno ORDER BY sto_isim ASC");
while ($a= mysql_fetch_array($fis_cek)){
$sth_adet = $a['cnt'];
$sth_tutar = $a['sum'];
$sto_isim = $a['sto_isim'];
echo'
<tr>
<td align="left">'.$sto_isim.'</a></td>
<td align="center">'.$sth_adet.'</td>
<td align="right">'.$sth_tutar.'</td>
</tr>';}}
我决定使用准确的日期值并且它没有任何问题..
正如您在图片中看到的,我使用这些代码列出来自 mysql 数据库的产品:
$satis_cek = mysql_query("SELECT * FROM satislar WHERE zno = '".$zno."'");
$varmi = mysql_num_rows($satis_cek);
$toplam_tutar = 0;
$indirim = 0;
$genel_toplam = 0;
if($varmi == ""){
$ara_toplam = 0;
$indirim_toplam = 0;
$genel_toplamlar= 0;
}else{
while ($satis_al = mysql_fetch_array($satis_cek)){
$sat_fatura_no = $satis_al['sat_fatura_no'];
$personel = $satis_al['sat_uye_id'];
$sat_tarih = $satis_al['sat_tarih'];
$sat_tip = $satis_al['sat_tip'];
$toplam_tutar += $satis_al['toplam_tutar'];
$indirim += $satis_al['indirim'];
$genel_toplam += $satis_al['genel_toplam'];
$fis_cek = mysql_query("SELECT * FROM stok_hareketleri WHERE sth_fatura_no = '".$sat_fatura_no."'");
while ($a= mysql_fetch_array($fis_cek)){
$sth_stok_kodu = $a['sth_stok_kod'];
$sth_adet = $a['sth_adet'];
$sth_tutar = $a['sth_tutar'];
$stok_cek = mysql_query("SELECT * FROM stoklar WHERE sto_RECno = '".$sth_stok_kodu."'");
while ($stok_al = mysql_fetch_array($stok_cek)){
$sto_isim = $stok_al['sto_isim'];
echo'
<tr>
<td align="left">'.$sto_isim.'</a></td>
<td align="center">'.$sth_adet.'</td>
<td align="right">'.$sth_tutar.'</td>
</tr>';}}}}
如图所示,我尝试列出一次 Jack Daniel's 并计算其销售数量和销售价格的总和,并将它们打印在 html table 行。
例如:
Jack Daniel's 2 220.00
Yeni Rakı 70 cl 1 85.00
Fanta 330 ml 1 3.00
我是 php 的新手,所以我无法解决如何使用相同 mysql table 的销售数量总和和价格总和来显示每个产品一次的问题。
这样尝试:table1
是产品详情 table,table2
是已售商品 table。
select sto_isim,sum(sth_tutar) as sum,sum(sth_adet) as cnt from table1 join table2 on table1.sto_RECno=table2.sth_stok_kod group by sto_RECno
这应该为每个产品提供单行以及总和和计数。
$tarih2 = date("Y-m-d 00:00:00",strtotime($_POST['tarih']));
$tarih3 = date("Y-m-d 23:59:59",strtotime($_POST['tarih']));
$satis_cek = mysql_query("SELECT * FROM satislar WHERE zno = '".$zno."'");
$varmi = mysql_num_rows($satis_cek);
$toplam_tutar = 0;
$indirim = 0;
$genel_toplam = 0;
if($varmi == ""){
$ara_toplam = 0;
$indirim_toplam = 0;
$genel_toplamlar= 0;
}else{
while ($satis_al = mysql_fetch_array($satis_cek)){
$sat_fatura_no = $satis_al['sat_fatura_no'];
$personel = $satis_al['sat_uye_id'];
$sat_tarih = $satis_al['sat_tarih'];
$sat_tip = $satis_al['sat_tip'];
$toplam_tutar += $satis_al['toplam_tutar'];
$indirim += $satis_al['indirim'];
$genel_toplam += $satis_al['genel_toplam'];}
$fis_cek = mysql_query("select sto_isim,sum(sth_tutar) as sum,sum(sth_adet) as cnt from stoklar join stok_hareketleri on stoklar.sto_RECno=stok_hareketleri.sth_stok_kod WHERE stok_hareketleri.sth_create_date >= '".$tarih2."' AND stok_hareketleri.sth_create_date <= '".$tarih3."' AND sth_tip = 'Satış Fişi' group by stoklar.sto_RECno ORDER BY sto_isim ASC");
while ($a= mysql_fetch_array($fis_cek)){
$sth_adet = $a['cnt'];
$sth_tutar = $a['sum'];
$sto_isim = $a['sto_isim'];
echo'
<tr>
<td align="left">'.$sto_isim.'</a></td>
<td align="center">'.$sth_adet.'</td>
<td align="right">'.$sth_tutar.'</td>
</tr>';}}
我决定使用准确的日期值并且它没有任何问题..