我不知道爲什麼服務器在$ array_transactions定義後立即停止。我試圖在該行之前回顯文本,它會顯示,但如果我在該行之後放置文本,則不會。爲什麼while循環沒有繼續?爲什麼在定義MySQL查詢後停止?
<?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)));
}
?>
是'mysql_error'返回什麼? – Mureinik 2014-12-07 17:03:03
不確定有關php/mysql中的連接,但它是因爲2個結果查詢'$ array'和'$ array_transactions'在同一連接'$ con'上同時打開嗎? – Rhumborl 2014-12-07 17:05:54
沒有錯誤報告@Mureinik和我也嘗試刪除括號,但也沒有工作。 – user3765935 2014-12-07 17:11:53