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 10 of 10
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    58
    Thanks
    3
    Thanked 0 Times in 0 Posts

    how to sell items in PHP

    how do i sell items in php? like text based game items..when a user has a item it goes to users_items table but i dont know how to make it so it can be sellable and add gold to the table users when a item is sold..

    so far all i have is this which shows all the items the user has...i looked at the tutorial in the admins signature but it didnt help me when it comes to something like this though...

    Code:
    <?php session_start();
    
    if(isset($_SESSION['otherusername'])){
    
    $db=mysql_connect('localhost', 'root', '');
    
    $res=mysql_select_db('textgame',$db) or die(mysql_error());
    
        
    $otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'";
        
        $res=mysql_query($otherusername)or die(mysql_error());
        
      
        while($row = mysql_fetch_assoc($res)){
    
    
         echo $row['item'] . "<BR />";
      
      }
    }else{
       
       echo "Sorry your not a member please join us!";
    }
    
    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Add a "sell" link to each item. Add a function when that link is clicked to update the table where you store the player's gold total and delete the item.

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    58
    Thanks
    3
    Thanked 0 Times in 0 Posts
    how can i give it a sell link if its echoing out of my database?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Um... the same way you create a link in html, like this:

    Code:
    <a href="sell.php">sell item</a>

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    58
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i think where on the right track..but..how can i give a field in a table a link? i dont really get it..each item is in the database.... and i have a table called users_items that has all the items the users have..

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Use the query string in the URL to pass the unique key of the table.

    For information on query strings:

    http://en.wikipedia.org/wiki/Query_string

    http://www.webopedia.com/TERM/Q/query_string.html

    http://whn.vdhri.net/2005/10/how_to_...ng_in_php.html

  • #7
    New Coder
    Join Date
    May 2008
    Posts
    58
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thxs!

    i'll check it out!

  • #8
    New Coder
    Join Date
    May 2008
    Posts
    58
    Thanks
    3
    Thanked 0 Times in 0 Posts
    so far i got this...
    any help?

    Code:
    <?php session_start();
    
    if(isset($_SESSION['otherusername'])){
    
    $db=mysql_connect('localhost', 'root', '');
    
    $res=mysql_select_db('textgame',$db) or die(mysql_error());
    
        
    $otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'";
        
        $res=mysql_query($otherusername)or die(mysql_error());
        
      
        while($row = mysql_fetch_assoc($res)){
    
    
    echo '<a href="sell.php?item="' . $row['item'] . '">' . $row['item'] . "<BR />";
      
      }
    }else{
       
       echo "Sorry your not a member please join us!";
    }
    
    ?>

  • #9
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Is "item" the primary key in your table? If not then you need to use that.

    Make sure you create valid html; you need a closing </a> tag.

  • #10
    New Coder
    Join Date
    May 2008
    Posts
    58
    Thanks
    3
    Thanked 0 Times in 0 Posts
    item is the primary key..


  •  

    Posting Permissions

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