#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    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...)


  2. #2
  3. No Profile Picture
    worshipper of DOT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Halmstad, Sweden
    Posts
    35
    Rep Power
    15
    <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

Similar Threads

  1. Can anyone help with mysql query and results?
    By msmith29063 in forum MySQL Help
    Replies: 3
    Last Post: February 8th, 2004, 04:43 AM
  2. Sorting MySql results by nearest to furthest away
    By highlander5430 in forum MySQL Help
    Replies: 7
    Last Post: January 25th, 2004, 02:40 PM
  3. Overwriting mysql query with the query results
    By onerandomday in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 05:45 AM
  4. mysql results into session array
    By TuxLives in forum PHP Development
    Replies: 10
    Last Post: January 6th, 2004, 02:09 PM
  5. PHP Code in mySQL results
    By NightShade737 in forum PHP Development
    Replies: 2
    Last Post: January 3rd, 2004, 11:53 AM

IMN logo majestic logo threadwatch logo seochat tools logo