Jump to content
MakeWebGames

Donator Days Market SQL?


Naffer20

Recommended Posts

So basically i just copied my crystal market into this, i just need a SQL for it, anyone got any idea what it would be? :)

<?php
include "globals.php";
$_GET['ID'] = isset($_GET['ID']) && is_numeric($_GET['ID']) ? abs(@intval($_GET['ID'])) : false;
print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'> Donator Days Market </h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'><br> <br><br>";
$_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : "";
switch($_GET['action'])
{
case "buy":
donatordays_buy();
break;

case "remove":
donatordays_remove();
break;

case "add":
donatordays_add();
break;

default:
donatordaysmarket_index();
break;
}
function donatordaysmarket_index()
{
global $db,$ir,$c,$userid,$h;
print " 

<a href='donatordaysmarket.php?action=add'> Add A Listing</a><br /><br />
Viewing all listings...
<table width=75% cellspacing=1 class='table'> <tr style='background:gray'> <th>Adder</th> <th>Qty</th> <th>Price each</th> <th>Price total</th> <th>Links</th> </tr>";
$q=$db->query("SELECT dm.*, u.* FROM donatormarket dm LEFT JOIN users u ON u.userid=dm.dmADDER ORDER BY dmPRICE/dmQTY ASC");
while($r=$db->fetch_row($q))
{
if($r['dmADDER'] == $userid) { $link = "<a href='dday.php?action=remove&ID={$r['dmID']}'>Remove</a>"; } else { $link = "<a href='dday.php?action=buy&ID={$r['dmID']}'>Buy</a>"; }
$each= abs(intval($r['dmPRICE'] / $r['dmQTY']));
print "\n<tr> <td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td> <td>{$r['dmQTY']}</td> <td> \$" . number_format($each)."</td> <td>\$".number_format($r['dmPRICE'])."</td> <td>[$link]</td> </tr>";
}
print "</table></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
}
function donatordays_remove()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT * FROM `donatordaysmarket` WHERE `dmID`={$_GET['ID']} AND `dmADDER`=$userid");
if(!$db->num_rows($q))
{
print "Error, either these donator days do not exist, or you are not the owner.<br /><br /> 
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
$h->endpage();
exit;
}
$r=$db->fetch_row($q);
$db->query("UPDATE `users` SET `donatordays`=`donatordays`+{$r['dmQTY']} where `userid`=$userid");
$db->query("DELETE FROM `donatordaysmarket` WHERE `dmID`={$_GET['ID']}");
print "Donator Days removed from market!<br /><br /> 
<a href='donatordaysmarket.php'>Back</a> </div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div> ";
}
function donatordays_buy()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT * FROM donatordaysmarket dm WHERE dmID={$_GET['ID']}");
if(!$db->num_rows($q))
{
print "Error, either these donator days do not exist, or they have already been bought.<br /> <br /> 
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
$h->endpage();
exit;
}
$r=$db->fetch_row($q);
if($r['dmPRICE'] > $ir['money'])
{
print "Error, you do not have the funds to buy these donator days.<br /><br /> 
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
$h->endpage();
exit;
}
$db->query("UPDATE `users` SET `donatordays`=`donatordays`+{$r['dmQTY']} where `userid`=$userid");
$db->query("DELETE FROM `donatormarket` WHERE `dmID`={$_GET['ID']}");
$db->query("UPDATE `users` SET `money`=`money`-{$r['dmPRICE']} where `userid`=$userid");
$db->query("UPDATE `users` SET `money`=`money`+{$r['dmPRICE']} where `userid`={$r['dmADDER']}");
event_add($r['dmADDER'],"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> bought your {$r['dmQTY']} donator days from the market for \$".number_format($r['dmPRICE']).".",$c);
print "You bought {$r['dmQTY']} donator days from the market for \$".number_format($r['dmPRICE']).".<br /> <br />
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";

}
function donatordays_add()
{
global $db,$ir,$c,$userid,$h;
$_POST['amnt'] = abs(@intval($_POST['amnt']));
$_POST['price'] = abs(@intval($_POST['price']));
if($_POST['amnt'])
{
if($_POST['amnt'] > $ir['donatordays'])
{   
print "You are trying to add more donator days to the market than you have. <br /><br /> 
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
$h->endpage();
exit;  
}
$tp=$_POST['amnt']*$_POST['price'];
$db->query("INSERT INTO `donatordays` VALUES('',{$_POST['amnt']},$userid,$tp)");
$db->query("UPDATE `users` SET `donatordays`=`donatordays`-{$_POST['amnt']} WHERE `userid`=$userid");
print "Donator Days added to market!<br /><br /> 
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
$h->endpage();
exit;
}


if($ir['donatordays']==0)
{
print"You have no donator days.<br /> <br />
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div>";
}

else
{
print " <b>Adding a listing...</b><br /><br />
You have <b>{$ir['donatordays']}</b> donator days(s) that you can add to the market.<form action='donatordaysmarket.php?action=add' method='post'>
   <table width=100% class =table  border=2 align='center'><tr>
<td>Donator Days:</td> <td><input type='text' STYLE='color: black;  background-color: white;' name='amnt' value='{$ir['donatordays']}' /></td></tr><tr>
<td>Price Each:</td> <td><input type='text' STYLE='color: black;  background-color: white;' name='price' value='200' /></td></tr><tr>
<td colspan=2 align=center><input type='submit' STYLE='color: black;  background-color: white;' value='Add To Market' /></tr></table></form><br /> 
<a href='donatordaysmarket.php'>Back</a></div><div><img src='images/generalinfo_btm.jpg' alt='' /></div><br></div></div></div></div></div> ";
}
}
$h->endpage();
?> 
Edited by Dominion
added php tags
Link to comment
Share on other sites

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.   Paste as plain text instead

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