Thread: method madness
View Single Post
Old 05-18-2008, 12:54 AM   #7 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Izym View Post
It doesn't, have a look at PHP: mysql_result - Manual. It should return as an array yes, but try write "print_r($result);" instead of "print $result;", since print can't handle arrays (which print_r was made for).
A quick response to the quoted post (whilst waiting for the OP to get back to us), here are some comments to chew on.

The initial statement is correct, VI said that mysql_result requires three arguments; it doesn't, only requires two arguments with the third field name/offset being optional. I think there may be some confusion over what this function does. The manual should clear that up for anyone not quite clear.

However from that point onwards the post strays a little. I'm going to assume that "it" (in "It should return as an array") references the return value of the getone method as that seems most appropriate. It should not be returning an array at all since the method is get one not get array. Since the method will only return FALSE or the row-column value there's no need in this case to use print_r over print as they will behave similarly. That said, in general, functions like print_r and var_dump are useful tools for taking a peek at things. If "it" refers to the local variable within getone there's again no reason to assume that it should be an array, it's likely not to be one if the class architecture is anything resembling useful.

If you're talking about mysql_result returning an array, I've no idea where you got that notion.

Finally, print can "handle" arrays (in that it doesn't return an error) by doing its job of printing a string representation of the argument (Array).

OP, please chime in with some responses.
Salathe is offline  
Reply With Quote