sql 공부중에 질문드립니다.

sql 공부중에 질문드립니다.

QA

sql 공부중에 질문드립니다.

본문

sql을 기초 공부하고있는중에 질문이 생겨서 문의드립니다.

<?php
ob_start();
include_once($_SERVER['DOCUMENT_ROOT'] ."/common.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/head.php");


$is_title="";


$sql="select * from g5_member where mb_1 ='서울대학교'";
$result=sql_query($sql);
?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>회원내역</title>
</head>
<body>
<table>
<tr>
<th>회원아이디</th>
<th>이름</th>
<th>연락처</th>
<th>포인트</th>
<th>출신학교</th>
</tr>
 <?php
    for ($i=0; $list = sql_fetch_array($result); $i++) {
?>
<tr>
<td><?php echo $list['mb_id']?></td>
<td><?php echo $list['mb_name']?></td>
<td><?php echo $list['mb_hp']?></td>
<td><?php echo $list['mb_point']?></td>
<td><?php echo $list['mb_1']?></td>
</tr>
<?php }?>
</table>

<div>

회원중 mb_1이 서울대학교인 사람들의 포인트 총금액

</div>

</body>
</html>

 

이렇게해서 다 출력은 되는데 

바디 하단부분 div 안에 회원중 mb_1이 서울대학교인 사람들의 포인트 총금액을 넣고 싶은데 어떻게 넣어야 할지 몰라서 질문드립니다.

이 질문에 댓글 쓰기 :

답변 3

$totalpoint = 0;

for ($i=0; $list = sql_fetch_array($result); $i++) {

if($list['mb_1'] == '서울대학교')  {

    $totalpoint += $list['mb_point'];

}

 

...

 

}
echo $totalpoint;

 

진서기님 소스에서 조건문 추가~

 


$sql = "
  select sum(mb_point) as sum_point
    from g5_member
   where mb_1 = '서울대학교'
";
$row = sql_fetch($sql);
$sum = $row['sum_point'];
echo $sum;
답변을 작성하시기 전에 로그인 해주세요.
전체 720
QA 내용 검색
filter #sql ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT