The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
A better understanding of mysql results...
Discuss A better understanding of mysql results... in the PHP Development forum on Dev Shed. A better understanding of mysql results... PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 26th, 2000, 06:08 AM
|
|
Contributing User
|
|
Join Date: Feb 2000
Posts: 43
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
This may turn out to be a lengthy post, but I think I am a little confused on Mysql results. Actually, I know I am because I can never seem to get them right... Thanks in advance for any help.
Here's the scenario... I am having trouble understanding what is returned when I do a MYSQL_QUERY() and how to handle it in the program... I know it returns an array, but I don't know how to get what I want out of the array.
I know how to do a MYSQL_QUERY looking for a bunch of values, using :
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
while ($return=MYSQL_FETCH_ARRAY($return_array)) {
...do this...
}
[/code]
What if I am only expecting one return? Obviously I do not want to do a WHILE loop for the one return.. So in the instance of :
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$return_array=MYSQL_QUERY("SELECT userid, password FROM table WHERE userid='$user_name'");
[/code]
I am only expecting one result, how do I get it out? I tried :
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$return=MYSQL_FETCH_ARRAY($return_array);
echo $return['userid'];
echo $return['password'];
[/code]
but that doesn't seem to work either... I don't know how to use MYSQL_FETCH_ROW (I looked on php.net and couldn't see a real difference in .._ROW and .._ARRAY but I still could never get ROW to work... Also, in the code above (fetching the userid/password) I get a MYSQL error if there is no matching userid... do I have to account for this possibility in my code, or am I just possibly doing something wrong with my usage?
I guess what I'm fetching for is information regarding returns from a QUERY, and how to handle them, a website would be nice if there is one out there... also, if you know of somewhere to find a bit of information on cookies in php... I got the setcookie part, and I understand the majority of that, but I'm reading about some browsers not handling this and that, and people using a header() function for their cookies, and I would like to know what that is all about... if anyone knows of a site that details that kind of information (again, been to php.net, that wasn't too helpful...)
|

April 27th, 2000, 03:39 AM
|
|
worshipper of DOT
|
|
Join Date: Jan 2000
Location: Halmstad, Sweden
Posts: 35
Time spent in forums: 5 h 5 m 13 sec
Reputation Power: 14
|
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by mmccue:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$return_array=MYSQL_QUERY("SELECT userid, password FROM table WHERE userid='$user_name'");
[/code]
I am only expecting one result, how do I get
[/quote]
With that query? No ..
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
it out? I tried :
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$return=MYSQL_FETCH_ARRAY($return_array);
echo $return['userid'];
echo $return['password'];
[/code]
[/quote]
"userid" will be in $return[0] and "password" in $return[1] ..
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
but that doesn't seem to work either... I don't know how to use MYSQL_FETCH_ROW (I looked on php.net and couldn't see a real difference in .._ROW and .._ARRAY but I still could never get ROW to work... Also, in the code above (fetching the userid/password) I get a MYSQL error if there is no matching userid... do I have to account for this possibility in my code, or am I just possibly doing something wrong with my usage?
[/quote]
If I'm not totally wrong, in which case some of the "gurus" around here will surely notice, using mysql_fetch_row() and the above query would result in $return["userid"] and $return["password"] ..
Forgive me if I'm wrong ..
Anyways, get a copy of "PHP3: Programming Browser Based Applications" by David Medinets, it's a good book if you need the fundamentals of stuff like queries and cookies ..
------------------
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Linux, the operating system with a clue - Command Line User Environment.[/quote]
geeee... thanks!
/closecut
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|