Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post

    Getting from Database

    In one table of my database called 'users' I store values called `id`, `giftID`, `gifttitle` and `value`.

    In another called 'gifts' I store `id`, `gifttitle`, `image` and `value`.

    Now, I need to be able to call the id from users to grab the gift title, image and value that the user has selected.

    How would I be able to do this?

    I tried using this code:
    PHP Code:
    <?php
        $ugid 
    $_SESSION['id'];
        
    $giftresult mysql_query("SELECT * FROM users WHERE id='$ugid'");
        
    $giftusers mysql_fetch_array($giftresult);
        
    $giftid $giftusers['giftID'];
        
        
    $result mysql_query("SELECT * FROM gifts WHERE id='$giftid'");
        while(
    $list mysql_fetch_array$result )){
        echo 
    $list['giftID'];
        }
    ?>
    However that just lists all the gift id in the users field stored in the database.

    Thanks.

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    159
    Thanks
    2
    Thanked 15 Times in 15 Posts
    If I understood correctly:

    PHP Code:
    $result mysql_query("SELECT * FROM users, gifts WHERE users.id = '$ugid' && gifts.id = users.giftID");
    $list mysql_fetch_array$result );
    echo 
    $list['gifttitle']; 
    That code should give you the giftTitle that corresponds to the giftID stored in your `users` table...

    And likewise $list['image'] should give you the image etc etc

    ~Jordan
    Last edited by JordanW; 03-03-2010 at 11:17 PM.
    Remember The Thank You Button Is Your Friend =]

    [ PHP / Javascript / VisualBasic / HTML / DHTML / CSS / .NET / MySQL ]

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Ya, i think thats right, you just didnt change the echo to the correct column


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •