2014-12-07 1 views
0

$ 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)));           
} 

?> 
+1

'아무것도 반환 mysql_error' 있습니까? – Mureinik

+0

php/mysql의 연결에 대해서는 확실하지 않지만'$ array'와'$ array_transactions'의 결과 쿼리가 모두 같은 연결'$ con'에서 동시에 열려 있기 때문에입니까? – Rhumborl

+0

@Mureinik과 괄호 제거를 시도했지만 오류가보고되지 않았습니다. – user3765935

답변

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)));           
    } 

?> 
+0

코드가 많이 있습니다. 변경 사항 (있을 경우)을 설명해 주시겠습니까? – Rhumborl

+0

php 변수 연결 문제가 간단합니다. ""$ userid. "'sql에서'$ userid'의 insted –

관련 문제