Jump to content
MakeWebGames

Recommended Posts

Posted

Hi all.

I'm having a bit of trouble with an inventory/item query.

I'm trying to select an item and it's quantity from the inventory, then compare it against a pre-defined variable. If the quantity is smaller than the predefined variable, a die() statement is outputted.

However, even if I have enough of the item, it still outputs the die() statement.

I'll post the bit of code that I'm working with.

$id = $db->query("SELECT iv.*,it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid = 107 WHERE iv.inv_userid = $userid LIMIT 1");
$r = $db->fetch_row($id);

And the IF and DIE statements:

elseif($r['inv_qty'] < $db_config['gym1bricks'])
	{
		die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some.");
	}

 

$db_config['gym1bricks'] is set to 3840. Yet, even if I have 40000, I still get the DIE() statement.

This is really getting to me now, as this is simple...ish, but I can't wrap my head around it.

Can anyone help me? Any help will be highly appreciated. :)

Posted

Re: Inventory help

is there something else above it to need the

else if

You should just need the

if

take the else out see if that its.

 

if that dont try this...

 

$run = sprintf("SELECT iv*, it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid = it.itmid WHERE iv.ivn_userid = %u AND it.itmid = %u",
 @intval($userid),
 @intval(107));

$runthis = $db->fetch_row($run);


if($runthis['inv_qty'] < $db_config['gym1bricks'])
     {
        die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some.");
     }

 

Also I dont know what the $db_config['gym1bricks'] is....

Posted

Re: Inventory help

It's in a nested IF statement:

 

elseif($ir['gymsize'] == 32)
{
	if($db->num_rows($query) <= 0)
	{
		die("You don't have any bricks to build your gym. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some.");
	}

	elseif($r['inv_qty'] < $db_config['gym1bricks'])
	{
		die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some.");
	}

	elseif($db->num_rows($query2) <= 0)
	{
		die("You don't have any cement to build your gym. Go <a href = 'buildgym.php?action=buycement' />here</a> to buy some.");
	}

	elseif($m['inv_qty'] < $db_config['gym1cement'])
	{
		die("You have cement, but you don't have enough. Go <a href = 'buildgym.php?action=buycement' />here</a> to buy some.");
	}

	elseif(($db->num_rows($query) <= 0) AND ($db->num_rows($query2) <= 0))
	{
		die("You don't have any bricks or cement to build your gym. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy bricks, and <a href = 'buildgym.php?action=buycement' />here</a> to buy cement.");
	} 

	else
	{
		$build1 = sprintf("UPDATE `users` SET `buildtime` = '%d',
						  `gymbuilt` = '%d'
						  WHERE `userid` = ('%u')",
						  $db_config['buildtime1'], 1, $userid);

		$db->query($build1);

		item_remove($userid, 107, $db_config['gym1bricks']);
		item_remove($userid, 108, $db_config['gym1cement']);

		print "You have now started work on your gym. It will be completed in {$db_config['buildtime1']} minutes. 



		<font color = 'red' /><b />NOTE: You can <u />NOT</u> change anything now, or cancel the construction of your gym.[/b]</font> 



		You will be able to access all other areas of Global Conflict 2250 during the construction of your gym. <a href = 'index.php' />Click Here</a> to go home.";
	}
}

 

But I can't see anything wrong with that...so it may be my SELECT query.

Posted

Re: Inventory help

Thank you.

Unfortunately, it still doesn't work.

I get this:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/home/*********/domains/*******/public_html/class/class_db_mysql.php on line 71

You have bricks, but you don't have enough. Go here to buy some.

I'm still getting the DIE() statement. :(

Why is this so hard!? :-P

Posted

Re: Inventory help

 

$run = sprintf("SELECT iv*, it.* FROM inventory iv LEFT JOIN items it ON iv.inv_itemid = it.itmid WHERE iv.ivn_userid = %u AND it.itmid = %u",
 @intval($userid),
 @intval(107));

$humm = $db->query($run);
$runthis = $db->fetch_row($humm);


if($runthis['inv_qty'] < $db_config['gym1bricks'])
     {
        die("You have bricks, but you don't have enough. Go <a href = 'buildgym.php?action=buybricks' />here</a> to buy some.");
     }


 

Maybe its me but i think i missed someething im still new to sprintf so try that one maybe i missed that....I'm sjure its just something small...like a typo or query typed wrong..

Posted

Re: Inventory help

Thank you so very much!!! It works a treat.

I just had to change a ivn to an inv and one other thing. :)

Thank you very much for helping me out. I will remember and practice this for when I need it again.

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