0

这有点令人困惑,因为它在某些记录上完美运行,而在其他记录上却不行。我正在尝试使用特定电子邮件提取所有记录,并且在大约一半的案例中只获得一条记录。我有两个查询集,一个是拉数据,一个是拉数据的一半。一直有效的第一个是:

$tiera = mysql_query("SELECT SUM(datamb) AS tiera FROM maindata2 WHERE dataplan = '2'  and    email='".mysql_real_escape_string($_POST['email'])."'");
$tiera1 = mysql_fetch_assoc($tiera); 
$tiera2 = $tiera1['tiera'];

$tieradata = mysql_query("SELECT SUM(dataplan) as datatotal FROM maindata2 WHERE dataplan =   '2' and email='".mysql_real_escape_string($_POST['email'])."'");
$tieradata1 = mysql_fetch_assoc($tieradata); 
$tieradata2 = $tieradata1['datatotal'];

echo "<table id='display1'>
            <tr>
                <th>Tier:</th>
                <th>Total Data in Tier:</th>
                <th>Data Usage This Period:</th>
                <th>Remaining:</th>

            </tr>";

echo "<tr>";
echo "<td>A</td> ";
echo "<td>". $tieradata2 . " MB</td> ";
echo "<td>". $tiera2. " MB</td> ";
echo "<td>".($tieradata1['datatotal'] - ROUND ($tiera1['tiera'],2)) . "MB</td></font> ";
echo "</table>";

我不能将它用于我的第二个查询,因为我需要它在这样的循环中:

$sql =  "SELECT phonenumber,date,email, dataplan AS currentplan, SUM(datamb) AS value_sum FROM maindata2 WHERE email='".mysql_real_escape_string($_POST['email'])."' GROUP BY dataplan, phonenumber ";


$result = mysql_query($sql);


if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No Data Found For This Email";
    exit;
}

$row = mysql_fetch_assoc($result);



$query = mysql_query($sql) or die(mysql_error());


$header_printed = false;

while($row = mysql_fetch_array($query)) {
if ($row['phonenumber']) {
    if ($header_printed === false) {
        echo "   
            <table id='display'>
            <tr>
                <th>Phone Number:</th>
                <th>Data Plan:</th>
                <th>Data Usage This Period:</th>
                <th>Remaining:</th>
        <th>Date Reporting:</th>
            </tr>";
        $header_printed = true;
    }




while ($row = mysql_fetch_assoc($result)){
 echo "<tr>";
 echo "<td>".$row['phonenumber'] . "</td> ";
 echo "<td>".$row['currentplan'] . "MB</td> ";
 echo "<td>".ROUND ($row["value_sum"],2) . "MB</td> ";
 echo "<td><font color=$color>".($row['currentplan'] - ROUND ($row["value_sum"],2)) .    "MB</td></font> ";
  echo "<td>".$row['date'] . "</td></tr>";

 } 
}
echo "</table>";

所以问题是,第一个查询中的第二个查询缺少什么?

4

0 回答 0