Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    I have a query that gets 2 columns from the table. Using PHP how do i get the contents of one column's on a row if i specify the other column value on the same row. (I am sure this is easy )

    Here is an example of what i am trying to do...
    Column1
    USA
    UK
    Canada

    Column2
    Washington DC
    London
    Ottawa

    If i was dumb and didn't know the capital city how could i use php to put in the country then get the capital?

    Thanks
    JR

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    PHP Code:
    $result mysql_query(...);
    while (
    $bits mysql_fetch_array($result))
    {
        
    // $bits['columnname'] for everything

    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    I don't understand. Well i already know how to do the fetch array and the query, i just don't understand what you mean by that comment.

    Basically what i am doing is working with sessions and users. I am getting the ID of the user, then checking if it matches the ID of the session and if it does i want to get the session start time on the same row as the specific ID i am checking for.

    What i am having problems with is getting the value in the session start time column on the same row as the ID.

    Hope i made sense
    JR

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Originally posted by JR
    What i am having problems with is getting the value in the session start time column on the same row as the ID.

    Hope i made sense
    Apparently not because if I do understand you correctly (and you know mysql_fetch_array correctly) then I'm lost.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Ok, it is pretty hard to explain ...
    Code:
    Column1   Column2
    5         hello
    7         goodbye
    2         bye
    I have already executed the query and done mysql_fetch_array to get these two columns.

    If i know i have the number 5 in Column1 (but don't know which number row it is on) and i want to get the value on the same row in Column2 what do i do. (using PHP)

    Sorry if the thread title is misleading because the mySQL part isn't the problem, its the bold part that is

    Thanks for putting up with my crap explanations and by the way that bold line is not me getting impatient, it is me making sure i am crystal clear about what my problem is
    JR

  7. #6
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Here is what worked for me. Not considering any optimization or anything, just working.

    PHP Code:

    <?

    // connect to server
    // select db

    $sql "SELECT id, value FROM series";
    $res mysql_query($sql);

    $knownColumn 'id';
    $knownValue 6;

    while(
    $array mysql_fetch_assoc ($res))
    {
        if(
    $array[$knownColumn] == $knownValue)
        {
            echo 
    "id: ".$array['id']." - value: ".$array['value']."<br>";
        }
    }
    ?>
    Hope this is what you were asking for
    There and Back Again :Ogre:

  8. #7
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    yes thanks a lot , now i need to apply it to what i am doing; will post if i have any problems
    JR


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:49 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com