开发者

MySQL, how to use returned data?

Well, I know there is a funciton mysql_fetch_array() and we can use it like this:

while ($row = mysql_fetch_array($result)) {
 echo $row['name'] . "<br />"; 
}

But is开发者_运维技巧 there any other way? For example, if there is only one element that can be returned, and not an array.

Thanks)


see mysql_result():

Retrieves the contents of one cell from a MySQL result set.


If there's only going to be one row then you can just say:

$row = mysql_fetch_array($result);

Or you can use mysql_fetch_row if you want.

But I'd second Erik's comment to go with PDO. Here's a good tutorial making heavy use of PDO.


You could use mysql_result

$result = mysql_query($query) or die(mysql_error());
$scalar = mysql_result($result, 0);


For example, if there is only one element that can be returned, and not an array.

Nope.
Only array or a useless object you can get.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜