1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to display info from and Mysql table using php

Discussion in 'PHP' started by micromark, Oct 12, 2007.

  1. #1
    Hi,


    I need to pull out some info from a table in my data base using php.

    
    
    <?php
    $result = mysql_query("SELECT 'giftlog.name', 'giftlog.image' FROM giftlog")
    
    
    
    
    
    LEFT JOIN    gifts
    
    USING (giftid)
    
    WHERE    giftlog.recipientid = " . $userid"
    
    ?>
    
    PHP:
    This is the code but it doesnt work.....lim a noob at the whole sql/php thing.
     
    micromark, Oct 12, 2007 IP
  2. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #2
    Thats because you have part of the MySQL query outside of the section that is being queried.
     
    crazyryan, Oct 12, 2007 IP
  3. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You must use following code

    
    $result = mysql_query("SELECT 'giftlog.name' AS name, 'giftlog.image' AS image FROM giftlog LEFT JOIN gifts USING (giftid) WHERE giftlog.recipientid = " . $userid);
    
    $row = mysql_fetch_assoc($result));
    
    echo $row['name'];
    echo $row['image'];
    
    PHP:
     
    Squash, Oct 12, 2007 IP
  4. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I get this -



    Parse error: parse error, unexpected ')' in /home/p/i/picturest/public_html/mygifts.php on line 5
     
    micromark, Oct 12, 2007 IP
  5. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Any1 got any idea's
     
    micromark, Oct 12, 2007 IP
  6. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry, I put redundant bracket.

    Correct line is:

    
    $row = mysql_fetch_assoc($result);
    
    PHP:
     
    Squash, Oct 12, 2007 IP
  7. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result
     
    micromark, Oct 12, 2007 IP
  8. emptyinside

    emptyinside Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    there is a problem with your $result

    try this
    
    $result = mysql_query("SELECT `giftlog`.`name` AS name, `giftlog`.`image` AS image FROM `giftlog` LEFT JOIN `gifts` ON `giftlog`.`giftid` = `gifts`.`giftid` WHERE `giftlog`.`recipientid` = " . $userid);
    
    
    PHP:
    However, i see you dont' pull any fields from the gifts table, so i can't see why you are using the LEFT JOIN
     
    emptyinside, Oct 12, 2007 IP
  9. micromark

    micromark Peon

    Messages:
    466
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ok it displays nothing --which is better then an error !
     
    micromark, Oct 12, 2007 IP
  10. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If you can provide access to your database for example via phpMyAdmin maybe I will be able to help you.
     
    Squash, Oct 15, 2007 IP