function rental_market()
{
global $ir;
if(isset($_GET['id']))
{
$houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `users` ON (`userid` = `uhouseTenant`) WHERE `uhouseTenant` > '0'"));
$house = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseId` = '%u')", abs((int) $_GET['id'])));
$r = mysql_fetch_assoc($house);
if(!mysql_num_rows($house))
{
echo 'You cannot rent a house that does not exist.';
}
else if($ir['money'] < $owned_houses['uhouseRent']*$owned_houses['uhouseRTime'])
{
echo 'You cannot afford this house.';
}
else if($ir['money'] > $owned_houses['uhouseRent']*$owned_houses['uhouseRTime'])
{
mysql_query(sprintf("UPDATE `users` SET `money` = `money` - '%d' WHERE `userid` = '%u'", $r['uhouseRent'], $r['uhouseTenant']));
mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseTenant` = '%d' WHERE (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
echo 'You are now renting the '.stripslashes($r['hNAME']).' for a total of $'.number_format($r['uhouseRent']).' each night!';
}
}
else
{
$houses = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE `uhouseTenant` = '0' AND `uhouseRent` > '0' ORDER BY `uhouseRent` ASC"));
echo '<table width="600" class="table">
<tr>
<th>House name</th>
<th>Owner</th>
<th>Will value</th>
<th>Cost each night</th>
<th>Rental time</th>
<th>Manage</th>
</tr>';
while($r = mysql_fetch_assoc($houses))
{
echo '<tr>
<td>'.stripslashes($r['hNAME']).'</td>
<td><a href=viewuser.php?id='.$r['userid'].'
>'.stripslashes($r['username']).'</a></td>
<td>'.number_format($r['uhouseMood']).' Will bar</td>
<td>$'.number_format($r['uhouseRent']).'</td>
<td>'.number_format($r['uhouseRTime']).' nights</td>
<td><a href=houses.php?page=rentals&id='.$r['uhouseId'].'>Rent house</a></td>
</tr>';
}
print '</table>';
}
}
function rent_house()
{
global $ir;
$fetch = mysql_query(sprintf("SELECT * FROM `owned_houses` LEFT JOIN `houses` ON (`hID` = `uhouseHouse`) LEFT JOIN `users` ON (`userid` = `uhouseOwner`) WHERE (`uhouseOwner` = '%u') AND (`uhouseId` = '%u')", $ir['userid'], abs((int) $_GET['id'])));
if(!isset($_GET['id']))
{
echo 'You did not select a house to rent out to members.';
}
else if(!mysql_num_rows($fetch))
{
echo 'You cannot attempt to rent out a non-existant house.';
}
else
{
$r = mysql_fetch_assoc($fetch);
if($r['uhouseOwner'] != $ir['userid'])
{
echo 'You do not own this house, so don\'t attempt to rent it out to people.';
}
else if($r['uhouseTenant'])
{
echo 'You cannot rent out a house while it is being rented to another member.';
}
else
{
if(isset($_POST['time']) AND isset($_POST['cost']))
{
mysql_query(sprintf("UPDATE `owned_houses` SET `uhouseRent` = '%d', `uhouseRTime` = '%d' WHERE (`uhouseId` = '%u')", abs((int) $_POST['cost']), abs((int) $_POST['time']), abs((int) $_GET['id'])));
echo 'You have added the '.stripslashes($r['hNAME']).' the the rental market at a cost of $'.number_format($_POST['cost']).' per night.';
}
else
{
echo '<form action="houses.php?page=rent&id='.$_GET['id'].'" method="post">
<table width="600">
<tr>
<td><b>Amount of nights:</b></td>
<td><input type="text" name="time" value="30" /></td>
</tr>
<tr>
<td><b>Cost per nights:</b></td>
<td><input type="text" name="cost" value="250" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit rental" /></td>
</tr>
</table>
</form>';
}
}
im having problems getting the money to be removed from one user and added to the user renting anyone help?