views:

52

answers:

4

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)

+1  A: 

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.

Skilldrick
thank you), article bookmarked
aejo
A: 

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.

Col. Shrapnel
+3  A: 

see mysql_result():

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

You could use mysql_result

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