我不能为我的生活找出为什么服务器在$ array_transactions定义后立即停止。我尝试在该行之前回显文本并显示,但如果我将文本放在该行之后,那么它就不会。为什么while循环不能继续?
<?php
$date1 = mysql_query("SELECT *
FROM transactions
WHERE userid='$userid'
ORDER BY date ASC LIMIT 1",$con)
or die(mysql_error());
while($row = mysql_fetch_array($date1))
{
$date = date_create($row['date']);
}
function priceformat($price){
$newprice = round($price,2);
return $newprice;
}
$array = mysql_query("SELECT *
FROM transactions
WHERE userid='$userid'
ORDER BY date ASC",$con)
or die(mysql_error());
$currentdate = date("o-m-d");
while( (strtotime($date) <= strtotime($currentdate)) &&
($result = mysql_fetch_array($array)))
{
// Check if $date exists in transactions table
$array_transactions = mysql_query("SELECT *
FROM transactions
WHERE (userid='$userid')
AND (date='$date')",$con)
or die(mysql_error());
// If entries for $date exist, sum transactions
if(mysql_num_rows($array_transactions) > 0) {
while($row = mysql_fetch_array($array_transactions)) {
if($row['type'] == 'D') {
$balance_affect = $row['amount'] + $balance_affect;
} else {
$balance_affect = (0 - $row['amount']) + $balance_affect;
}
}
}
// Check if $date exists in trades table
// If entries for $date exist, sum trades
echo '<tr>';
echo '<td class="v-align-middle text-center">';
echo $result['date'];
echo '</td>';
echo '<td class="v-align-middle text-center">';
$currentbalance = $previousbalance + $balance_affect;
echo '$' . $currentbalance . '';
echo '</td>';
echo '<td class="v-align-middle text-center">';
echo '</td>';
echo '<td class="v-align-middle text-center">';
echo '$0';
echo '</td>';
echo '</tr>';
$previousbalance = $currentbalance;
$date = date("o-m-d",strtotime("+1 day", strtotime($date)));
}
?>
答案 0 :(得分:0)
<?php
$date1 = mysql_query("SELECT * FROM transactions WHERE userid=".$userid." ORDER BY date ASC LIMIT 1",$con) or die(mysql_error());
while($row = mysql_fetch_array($date1)){
$date = date_create($row['date']);
}
function priceformat($price){
$newprice = round($price,2);
return $newprice;
}
$array = mysql_query("SELECT * FROM transactions WHERE userid=".$userid." ORDER BY date ASC",$con) or die(mysql_error());
$currentdate = date("o-m-d");
while((strtotime($date) <= strtotime($currentdate)) && ($result = mysql_fetch_array($array))) {
// Check if $date exists in transactions table
$array_transactions = mysql_query("SELECT * FROM transactions WHERE userid=".$userid." AND date='".$date."' ",$con) or die(mysql_error());
// If entries for $date exist, sum transactions
if(mysql_num_rows($array_transactions) > 0) {
while($row = mysql_fetch_array($array_transactions)) {
if($row['type'] == 'D') {
$balance_affect = $row['amount'] + $balance_affect;
}else{
$balance_affect = (0 - $row['amount']) + $balance_affect;
}
}
}
// Check if $date exists in trades table
// If entries for $date exist, sum trades
echo '<tr>';
echo '<td class="v-align-middle text-center">';
echo $result['date'];
echo '</td>';
echo '<td class="v-align-middle text-center">';
$currentbalance = $previousbalance + $balance_affect;
echo '$' . $currentbalance . '';
echo '</td>';
echo '<td class="v-align-middle text-center">';
echo '</td>';
echo '<td class="v-align-middle text-center">';
echo '$0';
echo '</td>';
echo '</tr>';
$previousbalance = $currentbalance;
$date = date("o-m-d",strtotime("+1 day", strtotime($date)));
}
?>