Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
$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?
Posted
Updated 9-Sep-13 10:08am
v2
Comments
Mohibur Rashid 4-Sep-13 4:00am    
check your f0, f1 and f2. if they are not proper value returned value might be empty

1 solution

PHP
mysql_query("set character set 'utf8'");


has to be put before

PHP
$result=mysql_query($query);


and it works fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900