TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-16-2008, 04:03 PM   #1 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default method madness

ok, i think i've run into a problem but, well here...

Code:
function getone($sql){
$result = $this->query($sql);

if(mysql_num_rows($result) == 0){
    $value = FALSE;
}
 else
    {
      $value = mysql_result($result, 0);
}
    return $value;
}
if i use this as
Code:
$EvSql = " SELECT username FROM users WHERE username ='".$_SESSION['usr_nme']."' ";
$result = $dbCon->getone($EvSql);
print $result;
SHOULD return that username, as $result, right? or did i not write that method correct?
i get no mysql errors, no log errors, no notices with E_all on.... it returns an empty var... or i think its empty...
in that function is $value an array, after returning it at the end?
i dont think it should be, not the way i understand things, that should return that 1 cells data out of the db table....
__________________
"Knowledge is power. Abuse it."~Evulness
My portfolio: www.evularts.com
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Old 05-16-2008, 04:06 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

mysql_result requires three parameters, the resource, row, and field name.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-17-2008, 07:48 PM   #3 (permalink)
The Contributor
 
Izym's Avatar
 
Join Date: Sep 2007
Posts: 32
Thanks: 0
Izym is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
mysql_result requires three parameters, the resource, row, and field name.
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).
Izym is offline  
Reply With Quote
Old 05-17-2008, 08:59 PM   #4 (permalink)
The Visitor
 
Join Date: May 2008
Posts: 1
Thanks: 0
skweegeasy is on a distinguished road
Default

Quote:
It doesn't, have a look at PHP: mysql_result - Manual
No, no, no, that's just YOUR opinion. Don't tell him his method of using three parameters is wrong, because his method works just fine for him. Also he doesn't believe in typecasting of any kind, so $result might not be an array, it could actually be a chocolate chip cookie for all we know.
skweegeasy is offline  
Reply With Quote
Old 05-17-2008, 09:17 PM   #5 (permalink)
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

Is the result from $this->query returning the expected result object? Is the return value really "empty", or FALSE (which would be returned when either no usernames match or when mysql_result fails). Use var_dump or some other debugging functions to spot problems rather than relying on error messages being raised to tell you what's wrong.

It's difficult to help you with debugging when we just get "help, it doesn't work" style requests. Debug everything, anything possibly related to the problem to make sure things are behaving as you expect (or not behaving!).
Salathe is offline  
Reply With Quote
Old 05-18-2008, 12:26 AM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot 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).
Whoops, my mistake. I've never used it with two rows.

And skwee, please don't slander me.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-18-2008, 12:54 AM   #7 (permalink)
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
Old 05-20-2008, 04:29 PM   #8 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default

sorry guys i've been down with a migraine for the last few days...
i switched it to print_r in my method, and its working, so far.... though heres something odd i found...

the result of a var_dump, on $result breaks the item selected into an array, making $result[1-9] = a letter of that item. aka pulling the username, breaks ths result down, if i print($result) it prints "Evulness" but if i print($result[1]); it returns E, 2 returns v, 3 returns u, etc...
if i print $result;, i get the full username....
odd... about how it breaks the username down into an array like that...

when i var_dump $result, it gives me
Quote:
string(7) "Evulness"
i was curious why it said 7, not knowing it counts the letters in the result. which is how i found it breaks each letter into its own entry in the array... var_dump ($result[3]); returns string (3) "l".

it looks like its working how i wanted, with it printing the result like that....
see i thought print would work, but print for some odd reason wasn't returning anything, it was in an array, and print($result) was returning result[0], which is empty... but print_r ($result), and print_r($result[0-7]) returned the username, and each letter as it was called...

Messing around like that just gave me a good idea for a feature for the cms.

thanks for pointing out print_r..... and i never thought of using var_dump.... i have a query output for debugging my mysql, but maybe i should put the var_dump and print_r into it too.
__________________
"Knowledge is power. Abuse it."~Evulness
My portfolio: www.evularts.com
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:59 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design