没有得到表中的行总和

没有得到表中的行总和

本文介绍了没有得到表中的行总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 $ query =   SELECT Distinct company,car_moto,packet FROM user where user ='$ userid'ORDER BY company,car_moto,packet; 
$ result = mysql_query($ query);
$ num = mysql_numrows($ result);

$ i = 0;
while ($ i< $ num){
$ f0 = mysql_result($ result,$ i, company);
$ f1 = mysql_result($ result,$ i, car_moto);
$ f2 = mysql_result($ result,$ i, packet);

$ sql_1 = SELECT SUM(price_protect)作为partpaid1 FROM公司,其中company ='$ f0'和car_moto ='$ f1'且packet ='$ f2'和userid ='$ userid';
$ sql_2 = SELECT SUM(clear_protect) )作为partpaid2 FROM公司='$ f0'和car_moto ='$ f1'和packet ='$ f2'和userid ='$ userid';
$ result_1 = mysql_query($ sql_1) die(' 错误查询失败');
$ result_2 = mysql_query($ sql_2) die(' 错误查询失败');

while ($ row_1 = mysql_fetch_array($ result_1)){
$ invoicepartpaid1 = $ row_1 [' partpaid1'];
}
while ($ row_2 = mysql_fetch_array($ result_2)){
$ invoicepartpaid2 = $ row_2 [' partpaid2'];
}
echo < ; tr>< td align ='center'><< span> $ f0< / span>< / td>< td align ='center'>< span> $ f1< / span>< / td>< td align ='center'>< span> $ f2< / span>< / td>< td align ='center'>< span> $ invoicepartpaid1& lt; / span> < / td>< td align ='center'>< span> $ invoicepartpaid2< / span>< / td>< / tr>;

$ i ++;

}





结果

< span> $ invoicepartpaid1< / span> ; 

< span> $ invoicepartpaid2< / span> 

为空。应该有钱。有什么建议吗?

解决方案




$query="SELECT Distinct company, car_moto, packet FROM companies where userid='$userid' ORDER BY company, car_moto, packet";
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;
while ($i < $num) {
  $f0=mysql_result($result,$i,"company");
  $f1=mysql_result($result,$i,"car_moto");
  $f2=mysql_result($result,$i,"packet");

  $sql_1 = "SELECT SUM(price_protect) as partpaid1 FROM companies where company='$f0' and car_moto='$f1' and packet='$f2' and userid='$userid'";
  $sql_2 = "SELECT SUM(clear_protect) as partpaid2 FROM companies where company='$f0' and car_moto='$f1' and packet='$f2' and userid='$userid'";
  $result_1=mysql_query($sql_1) or die('Error query failed');
  $result_2=mysql_query($sql_2) or die('Error query failed');

  while ($row_1 = mysql_fetch_array($result_1)) {
    $invoicepartpaid1 = $row_1['partpaid1'];
  }
  while ($row_2 = mysql_fetch_array($result_2)) {
    $invoicepartpaid2 = $row_2['partpaid2'];
  }
  echo "<tr><td align='center'><span>$f0</span></td><td align='center'><span>$f1</span></td><td align='center'>< span>$f2</span></td><td align='center'><span>$invoicepartpaid1& lt;/span></td><td align='center'><span>$invoicepartpaid2</span>< /td></tr>";

  $i++;

}



The Results of

<span>$invoicepartpaid1</span>

and

<span>$invoicepartpaid2</span>

are blank. There should be sums. Any suggestion?

解决方案




这篇关于没有得到表中的行总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 10:41