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:
    1.  
    2.  
    3. <?php
    4. $result = mysql_query("SELECT 'giftlog.name', 'giftlog.image' FROM giftlog")
    5.  
    6.  
    7.  
    8.  
    9.  
    10. LEFT JOIN    gifts
    11.  
    12. USING (giftid)
    13.  
    14. WHERE    giftlog.recipientid = " . $userid"
    15.  
    16. ?>
    17.  
    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

    PHP:
    1.  
    2. $result = mysql_query("SELECT 'giftlog.name' AS name, 'giftlog.image' AS image FROM giftlog LEFT JOIN gifts USING (giftid) WHERE giftlog.recipientid = " . $userid);
    3.  
    4. $row = mysql_fetch_assoc($result));
    5.  
    6. echo $row['name'];
    7. echo $row['image'];
    8.  
     
    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:

    PHP:
    1.  
    2. $row = mysql_fetch_assoc($result);
    3.  
     
    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
    PHP:
    1.  
    2. $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);
    3.  
    4.  
    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