mysql_result()函数介绍

mysql_result函数获取结果集中某一行某一列的字段值。

语法:

mysql_result(result,row,field)

参数:

参数 描述
data 必需。结果集。由mysql_query()函数返回的结果集。
row 必需。表示结果集中的哪一行
field

可选。表示结果集中的哪一列。可以是字段偏移值(偏移量从0开始)、字段名或 table.fieldname。

如果该参数未规定,则该函数从指定的行获取第一个字段。

 

mysql_result()使用实例:

比如本地数据库test_db里面有一张student表,表数据如下:

\"php

下面使用mysql_result函数操作该表:

<?php
     $con=mysql_connect(\"127.0.0.1\",\'root\',\'123\');
     $mysql_select_db(\"test_db\");
     $query = \"SELECT student_id, student_name FROM student\";
     $result = mysql_query($query);
     echo $productid = mysql_result($result, 6, \"student_id\").\'<br/>\';//获取结果集中第七行的student_id值
     /* http://www.manongjc.com/article/1243.html */
     echo $name = mysql_result($result, 4, \"student_name\");//获取结果集中第五行的student_name值
?>

输出结果:

7
Mathews

收藏 打印