Page 1 of 1

how to sell items in PHP

Posted: Thu Dec 18, 2008 4:00 pm
by redfox16
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: Select all

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

Re: how to sell items in PHP

Posted: Sat Dec 27, 2008 8:16 pm
by cptnwinky
In short the flow would go like this...

User marks item as sellable: UPDATE user_items SET sellable=true WHERE id=unique_id_of_item
Someone buys said item: UPDATE user_items SET user_id_of_owner=owner_id WHERE id=unique_id_of_item (same goes for whatever table and column the money is stored in. Update it to reflect the loss of one persons money and the gain of the others)

So, the item never gets deleted, just updated so that it now belongs to the other user. Does this make sense?