我有以下 PHP 代码:
echo "var s1 = [";
$count = 0;
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
if ($count++ > 0) echo ", ";
echo $row['OrdersBal'];
}
echo "];\n";
echo "var ticks = [";
$count2 = 0;
while($row2 = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
if ($count2++ > 0) echo ", ";
echo "'" . $row2['CardName'] . "'";
}
echo "];\n";
它目前正在输出:
var s1 = [37966.550000, 19876.170000, 17314.580000, 15614.410000, 7575.000000];
var ticks = [];
但我希望它输出:
var s1 = [37966.550000, 19876.170000, 17314.580000, 15614.410000, 7575.000000];
var ticks = ['Parameter Technology', 'Earthshaker Corporation', 'Microchips', 'Mashina Corporation', 'SG Electronics'];
如果我移动第二个 while 语句使其首先出现,那么该语句将正确输出。这让我相信我不能以这种方式连续执行两个 while 语句,但我不确定我的替代方案是什么。谢谢你的帮助!