+ Reply to Thread
Results 1 to 4 of 4

Thread: PHP & MySQL - LEFT JOIN issue

  1. #1
    nerdpowah23 is offline x10Hosting Member nerdpowah23 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    14

    PHP & MySQL - LEFT JOIN issue

    So I have a user_items table that has:
    userid (So it keeps track of who has the item)
    item_id

    However, I also have an items table that has:
    item_id
    item_name
    item_description
    item_type
    item_desc
    item_cost
    item_sell_value

    <?php require("styles/top.php"); ?>

    <?php
    if(isLoggedin($valid)){
    ?>

    <center><h1>Your Items</h1></center>
    <?php
    $query
    = mysql_query("SELECT items.item_id FROM items LEFT JOIN user_items ON
    items.item_id=user_items.item_id WHERE user_items.userid='
    $userid'");
    $numrows = mysql_num_rows($query);
    if(
    $numrows > 0){
    while(
    $row = mysql_fetch_assoc($query)){
    $name = $row['item_name'];
    echo
    "you have a $name";
    }
    } else {
    echo
    "You have no items.";
    }

    ?>



    <?php
    } else {
    ?>



    <?php
    }
    ?>
    When I try to echo out the name, it doesnt echo anything. Any ideas?

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: PHP & MySQL - LEFT JOIN issue

    At a quick glance:

    SELECT items.item_id

    only asks for the item_id. It doesn't return the item_name.
    Nothing is always absolutely so.

  3. #3
    nerdpowah23 is offline x10Hosting Member nerdpowah23 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    14

    Re: PHP & MySQL - LEFT JOIN issue

    That seems to work now, sorry I'm just trying to get this join stuff, I'm over-thinking everything.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP & MySQL - LEFT JOIN issue

    Did you color the sample code by hand? You don't need to do this; just use [php], [html], [code] or [c] (for inline code) tags as appropriate, which will also preserve formatting and better delineate the code.
    Last edited by misson; 06-25-2011 at 08:48 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. MySQL Join Question
    By learning_brain in forum Programming Help
    Replies: 1
    Last Post: 06-05-2011, 06:24 PM
  2. mysql join causing exception
    By the maya in forum Programming Help
    Replies: 0
    Last Post: 11-11-2009, 05:33 PM
  3. MySQL Join
    By jason32 in forum Programming Help
    Replies: 6
    Last Post: 08-01-2009, 08:26 PM
  4. Mysql+join+count
    By gptsven in forum Programming Help
    Replies: 9
    Last Post: 04-28-2009, 07:59 PM
  5. Join my forum and i will join your site
    By Daniel S in forum The Marketplace
    Replies: 4
    Last Post: 02-02-2008, 05:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers