Re: Sell all button
i took the code and pimped it out:
<?php
/*
-----------------------------------------
Just a little thing i came up with
-----------------------------------------
*/
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm);
$h->menuarea();
$_GET['ID'] = abs((int) $_GET['ID']);
$_GET['qty'] = make_bigint($_GET['qty']);
//itemsell
if($_GET['qty'])
{
$id=mysql_query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid=it.itmid WHERE iv.inv_id={$_GET['ID']} AND iv.inv_userid=$userid LIMIT 1",$c);
if(mysql_num_rows($id)==0)
{
print "Invalid item ID";
}
else
{
$r=mysql_fetch_array($id);
if($_GET['qty'] > $r['inv_qty'])
{
print "You are trying to sell more than you have!";
}
else
{
$price=$r['itmsellprice']*$_GET['qty'];
//are we sending it all
if($_GET['qty'] == $r['inv_qty'])
{
//just give them possession of the item
mysql_query("DELETE FROM inventory WHERE inv_id={$_GET['ID']}",$c);
}
else
{
//create seperate
mysql_query("UPDATE inventory SET inv_qty=inv_qty-{$_GET['qty']} WHERE inv_id={$_GET['ID']} LIMIT 1;",$c);
}
mysql_query("UPDATE users SET money=money+{$price} WHERE userid=$userid",$c);
$priceh="$".($price);
print "You sold {$_GET['qty']} {$r['itmname']}(s) for {$priceh}";
mysql_query("INSERT INTO itemselllogs VALUES ('', $userid, {$r['itmid']}, $price, {$_GET['qty']}, unix_timestamp(), '{$ir['username']} sold {$_GET['qty']} {$r['itmname']}(s) for {$priceh}')", $c);
}
}
}
else if($_GET['ID'])
{
$id=mysql_query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid=it.itmid WHERE iv.inv_id={$_GET['ID']} and iv.inv_userid=$userid LIMIT 1",$c);
if(mysql_num_rows($id)==0)
{
print "Invalid item ID";
}
else
{
$r=mysql_fetch_array($id);
print "
[b]Enter how many {$r['itmname']} you want to sell. You have {$r['inv_qty']} to sell.[/b]
<form action='itemsell.php' method='get'>
<input type='hidden' name='ID' value='{$_GET['ID']}' />
<table width=30% border=1><tr><td width=20% valign='top'>[b]<center>Quantity</center>[/b]</font></td><td>[b]Links[/b]</td>
<tr><td><input type='text' name='qty' value='' /></td><td><input type='submit' value='Sell Items' /></form></td><tr><td>Sell All You Have Of This Item</td><td><input type='submit' value='Sell All' /></form></td>
<form action='itemsell.php' method='get'>
<input type='hidden' name='ID' value='{$_GET['ID']}' />
<input type='hidden' name='qty' value='{$r['inv_qty']}' />";
}
}
else
{
print "Invalid use of file.";
}
$h->endpage();
?>
Its not brilliant but its a bit tidier, until someone makes it look better use this as the itemsell.php :? oh well im not that good a coder anyways.
If you want a screen shot check this http://img406.imageshack.us/img406/3342/isscreenshotap5.png