··조회 10,119
응용을 해보고 있습니다만..
전에 답변을 해주신 내용과 강의내용으로 응용을 해보고자 했는데
잘 안되어서 문의드립니다.
$row[a]=자료명 $row[b]=수량
$row[b]의 전체 합계수를 얻을려고 합니다.
//-------------------------------------------------------
$query="select * from 테이블명 by num desc";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
$auto=$total_record-$offset-$i;
$i++;
echo "<tr bgcolor='#FFFFFF'>
<td height='30' width='100'><p align='center'>$row[a]</p></td>
<td height='30' width='100'><p align='center'>$row[b]</p></td>
<td height='30' width='100'><p align='center'>$row[c]</p></td>
<td height='30' width='100'><p align='center'>$row[e]</p></td>
<td height='30' width='100'><p align='center'>$row[f]</p></td>
</tr>
";
}
잘 안되어서 문의드립니다.
$row[a]=자료명 $row[b]=수량
$row[b]의 전체 합계수를 얻을려고 합니다.
//-------------------------------------------------------
$query="select * from 테이블명 by num desc";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
$auto=$total_record-$offset-$i;
$i++;
echo "<tr bgcolor='#FFFFFF'>
<td height='30' width='100'><p align='center'>$row[a]</p></td>
<td height='30' width='100'><p align='center'>$row[b]</p></td>
<td height='30' width='100'><p align='center'>$row[c]</p></td>
<td height='30' width='100'><p align='center'>$row[e]</p></td>
<td height='30' width='100'><p align='center'>$row[f]</p></td>
</tr>
";
}
댓글 1
그러면 아래와 같이 SQL 명령으로 b 필드의 합을 바로 구하면 될 것 같은데요.
$sql = "select sum(b) from 테이블명";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
echo "$row[0]";