Jump to content

how to sell items in PHP


berry05

Recommended Posts

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...

 

<?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!";
}

?>

Link to comment
Share on other sites

i looked at the tutorial in the admins signature

 

What tutorial are you referring to?  Could you provide a link so we could get the info that you're basing your game off of?

 

Are you keeping this info in a database?  Is there an item table with a value for each item?

 

What are the major issues here.  All you said is that you don't know how to do something.  This looks more like a design issue...

 

You need to have a table for items with a value for each, and another table like "user_to_items" to keep track of what items each user has.

Link to comment
Share on other sites

You need to figure out a proper design for the application, database, and logic so that you don't run into these kinds of problems.

 

Currently you need to add a field called "gold_value" in the item table for each item so when users perform a transaction you know how much to add/subtract from each gold_count of each user.

Link to comment
Share on other sites

<?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!";
}

?>

 

You will have to create a "sell.php" to see the item, probably have a confirmation for them, ask them if they really want to sell it.

Link to comment
Share on other sites

when i hover over the items link  it has the URL and at the end it has sell.php?item=

 

and that's it..isn't it suppose to show the item name from the field?

 

echo '<a href="sell.php?item="' . $row['item'] . '">' . $row['item'] . "<BR />";

 

 

i think it has something to do with that code right there..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.