2013-05-17 2 views
0

PHP에서 열의 값의 합계를 얻으려고하고 있지만 그것은 MySQL에서 테스트 할 때 쿼리가 잘 작동하는 동안 전혀 작동하지 않습니다. 코드는 다음과 같습니다. 코드)PHP에서 열의 합계가 작동하지 않습니다

require('../_req/base.php'); 
$getCartQ = "select * from user_product inner join cart inner join products inner join users on user_product.User_ID = cart.User_ID and user_product.User_ID = users.User_ID group by cart.User_ID"; 
$getCartR = mysql_query($getCartQ); 
?> <table align="center" width="1271" border="0" cellpadding="0" cellspacing="0"> 

<?php 
while($cartRow = mysql_fetch_array($getCartR)){ 

    $sumQ = "select SUM(Total) as total from user_product where Status = 'active' and user_product.User_ID = '$cartRow[User_ID]'"; 
    $sumR = mysql_query($sumQ) or die(mysql_error()); 
    $sumRow = mysql_fetch_assoc($sumR); 
    $cost = $sumRow['total']; 
    ?> 
    <tr> 
    <td><?php echo $cartRow['Full_Name'] ?></td> 
    <td><?php echo $cartRow['State']; ?></td> 
    <td><?php echo $cost; ?></td> 
    </tr> 
    <?php 
} 
?> 
</table> 
<?php 
mysql_close($connect); 

내가 그 코드 뭐가 잘못 난 아무것도 단지 빈 공간 얻을 $ 비용을 에코하려고?

+0

PHP에는 mysql api를 사용하지 말아야한다. MySQLi 또는 PDO를 사용하십시오. PHP 5.5.0 이후로 더 이상 사용되지 않습니다 –

+0

쿼리 $ sumQ 바로 전에 연결 개체를 반향시키고 그것이 존재하는지 여부를 확인하십시오. –

+0

코드 블록 안에 "mysql_query"가있는 질문에 대한 자동 주석으로 "SQLite/PDO를 사용하지 마십시오"라는 autoposts가 내장 된 마법 함수가 있어야합니다. 사람들이 매일 쓰는 낭비되는 노동 시간을 생각해보십시오. – Uberfuzzy

답변

1
user_product.User_ID = '$getCartR[User_ID]'"; 

답변을해야합니다 고마워.

+0

나는 이것에 대해서도 말하려고했습니다 ... 다음에 모든 코드를 입력하십시오. 한 번 : –

+1

하지만'echo mysql_error();와 함께 나타나야합니다. –

1

는 말에

echo mysql_error(); 

을하고 그것을 보여주는 무슨 말해. 당신은

user_product.User_ID = '{$getCartR['User_ID']}'"; 
+0

그것은 당신이 제안한대로 작성된 것입니다 –

+0

@jqbeginner i edited ... –

+0

제공된 리소스는 유효한 MySQL 링크 리소스가 –

0

난 그냥 캐시를 삭제하고 모든 것이 내가이 모든 당신의 도움에 대한 캐시 덕분에 함께 할 수있다 모르겠어요 잘 작동에 바로

관련 문제