$re = mysql_query($sql)
list($sum)=mysql_fetch_row($re)
mysql_free_result($re)
echo "总和=$sum"
mysql_fetch_array()-获取和显示数据格式:
array mysql_fetch_array (resource result_set [, int result_type])
例:
$query = "select id, name from MyTable order by name"
$result = mysql_query($query)
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row["id"]
$name = $row["name"]
echo "Name: $name ($id) <br />"
}
又例:
$query = "select id, name from MyTable order by name"
$result = mysql_query($query)
while($row = mysql_fetch_array($result, MYSQL_NUM)) {
$id = $row[0]
$name = $row[1]
echo "Name: $name ($id) <br />"
}
说明:
result_type的值有:
MYSQL_ASSOC: 字段名表示键,字段内容为值
MYSQL_NUM: 数值索引数组, *** 作与mysql_fetch_ros()函数一样
MYSQL_BOTH: 即作为关联数组又作为数值索引数组返回。result_type的默认值。
10、mysql_fetch_assoc()-获取和显示数据
格式:
array mysql_fetch_assoc (resource result_set)
相当于调用 mysql_fetch_array(resource, MYSQL_ASSOC)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)