Php 为什么在定义MySQL查询后会停止?

Php 为什么在定义MySQL查询后会停止?,php,mysql,Php,Mysql,我一辈子都搞不懂为什么服务器在定义$array\u事务后立即停止。我试图在那一行之前回显文本,它会显示出来,但如果我把文本放在那一行之后,它就不会显示出来。为什么while循环没有继续 <?php $date1 = mysql_query("SELECT * FROM transactions WHERE userid='$userid' ORDER

我一辈子都搞不懂为什么服务器在定义$array\u事务后立即停止。我试图在那一行之前回显文本,它会显示出来,但如果我把文本放在那一行之后,它就不会显示出来。为什么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)));                                        
}

?>

是否
mysql\u error
返回任何内容?不确定php/mysql中的连接是否正确,但这是因为两个结果查询
$array
$array\u事务
同时在同一个连接上打开
$con
?没有报告任何错误@Mureinik,我也尝试删除括号,但这也没用。你可以在同一个连接上同时进行查询吗,@Rhumborl?@user3765935正如我说的,我不知道,但代码看起来不错,所以可能需要研究一下。那里有很多代码。您能解释一下您的更改吗(如果有)?php变量连接问题请尝试使用简单的
“$userid”。
代替sql中的
$userid
<?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)));                                        
    }

?>