-1

<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>";
echo "<td align='center'><span>$invoicepartpaid1</span></td><td align='center'><span>$invoicepartpaid2</span></td></tr>";

    $i++;

}
4

1 に答える 1

1

ラインを交換する

$num=mysql_numrows($result);

$num=mysql_num_rows($result);

完全なコード

<?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_num_rows($result);
    $i=0;
    while ($row=mysql_fetch_array($result)) {// loop for all results replacing $i < $num
        $f0=$row["company"];
        $f1=$row["car_moto"];
        $f2=$row["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');

        $invoicepartpaid1=0;$invoicepartpaid2=0;
        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>";
        echo "<td align='center'><span>$invoicepartpaid1</span></td><td align='center'><span>$invoicepartpaid2</span></td></tr>";
        $i++;
    }
?>
于 2013-09-04T08:12:17.560 に答える