legrolls Posted May 8, 2009 Posted May 8, 2009 I want it so if you have a tomato (ID 32), cheese (ID 33), and crust (ID 34), you can make a pizza (ID 35) I'm not really sure on how to do it, I know how to $db->query("INSERT INTO inventory VALUES('',35,$userid,1)"); but I'm stuck on how to make it so if they have the ingredients, they can make the food, but if they don't, it tells them they need the ingredients. Quote
_Eagle Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? could probably do it one of several ways. select those items like.. maybe.. $pizza=$db->query("SELECT * FROM inventory WHERE inv_itemid=32 && inv_itemid=33 && inv_itemid=34 AND inv_userid=$userid"); if($db->num_rows($pizza)){ $db->query("INSERT INTO inventory VALUES('',35,$userid,1)"); print"You made a pizza with all the required ingredients"; } else { print"You do not have all the required ingredients to create a pizza. You need Tomato, Cheese, and a Crust"; } that is one way possible. Course I am a rusty old sot.. others probably have a far better way. Quote
legrolls Posted May 8, 2009 Author Posted May 8, 2009 Re: If you have an item, you can create another? Still not working. If it makes any difference, it's mccodes v2 Quote
_Eagle Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? ok.. I will really honestly work on this. as I said.. that was one possible. another way would be to select all from a users inventory, then look for those particular items, 32, 33, and 34.. and if present, they can make the pizza. v2 code is not much different to write.. my game is still "v1".. if I had to version, prob v1.8 by now.. so much rewrite has gone on.. give me a bit.. I will find a workable solution for you. Quote
Haunted Dawg Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? $stuff = mysql_query("SELECT inv_id FROM `inventory` WHERE `inv_itemid` = 32 AND `inv_itemid` = 33 AND `inv_itemid` = 34"); if(mysql_num_rows($stuff)) { echo TRUE; } else { echo FALSE; } Quote
legrolls Posted May 8, 2009 Author Posted May 8, 2009 Re: If you have an item, you can create another? Where do I put that? Quote
_Eagle Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? he does not want it to just echo true or false though. he wants the system to give another item. Then, be sure to take that new item into account and be sure to wipe the ingredients, or you will find a whole ton of pizzas made on just one set of ingredients. Maybe this scenario. $pizza=$db->query("SELECT * FROM inventory WHERE inv_userid=$userid"); while($p=$db_fetch_row($pizza)) { if($p['inv_itemid']==32 && $p['inv_itemid']==33 && $p['inv_itemid']==34) { $db->query("INSERT INTO inventory VALUES('',35,$userid,1)"); $db->query("DELETE FROM inventory WHERE inv_itemid=32 and inv_userid=$userid LIMIT 1"); $db->query("DELETE FROM inventory WHERE inv_itemid=33 AND inv_userid=$userid LIMIT 1"); $db->query("DELETE FROM inventory WHERE inv_itemid=34 AND inv_userid=$userid LIMIT 1"); print"You have made a Pizza using all the need ingredients"; } else { print"You do not have the required ingredients to make pizza. You need to have Tomato, Cheese, and Crust."; } } Quote
legrolls Posted May 8, 2009 Author Posted May 8, 2009 Re: If you have an item, you can create another? Fatal error: Function name must be a string in /home/mylifeth/public_html/pizzamake.php on line 4... Quote
_Eagle Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? but I dont have all your file man.. you were asking about a query to give an item.. I am really trying to help you.. its not often I even speak on here.. Quote
Haunted Dawg Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? $stuff = mysql_query("SELECT inv_id FROM `inventory` WHERE `inv_itemid` = 32 AND `inv_itemid` = 33 AND `inv_itemid` = 34 AND `inv_userid` = ".$ir['userid']); if(mysql_num_rows($stuff)) { item_add($ir['userid'], 35, 1); item_remove($ir['userid'], 32, 1); item_remove($ir['userid'], 33, 1); item_remove($ir['userid'], 34, 1); echo 'You successfuly made a pizza!'; } else { echo 'You do not have the sufficient ingredients yet.'; } _Eagle, why select the entire inventory when only certain required? The above should work :) Quote
_Eagle Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? that is one way possible. Course I am a rusty old sot.. others probably have a far better way. Told ya. I am rusty.. not up to speed.. Quote
legrolls Posted May 8, 2009 Author Posted May 8, 2009 Re: If you have an item, you can create another? I have no php file yet. I just want to know how to make it work, it's still not working... Quote
Haunted Dawg Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? As i said: <?php include_once('globals.php'); echo '<h2>Lets Make Pizza!</h2>'; $stuff = mysql_query("SELECT inv_id FROM `inventory` WHERE `inv_itemid` = 32 AND `inv_itemid` = 33 AND `inv_itemid` = 34 AND `inv_userid` = ".$ir['userid']); if(mysql_num_rows($stuff)) { item_add($ir['userid'], 35, 1); item_remove($ir['userid'], 32, 1); item_remove($ir['userid'], 33, 1); item_remove($ir['userid'], 34, 1); echo 'You successfuly made a pizza!'; } else { echo 'You do not have the sufficient ingredients yet.'; } $h->endpage(); ?> Post any error's. Quote
legrolls Posted May 8, 2009 Author Posted May 8, 2009 Re: If you have an item, you can create another? I just don't know why, but it still says I don't have the sufficient ingredients. It's probably my fault, but I'm 100% sure they are the correct IDs, because I checked PHPMyAdmin and the game itself. Quote
AlabamaHit Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? well then check in the game to see if you have the items. Cause the code that Killah gave you looks 100% right. Quote
Lithium Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? Something along these lines... (using HD's code changing only the SQL statement <?php include_once('globals.php'); echo '<h2>Lets Make Pizza!</h2>'; $stuff = $db->query("SELECT `inv_id` FROM `inventory` WHERE `inv_id` IN (32, 33, 34) AND `inv_userid` = '{$ir['userid']}'"); if(mysql_num_rows($stuff)) { item_add($ir['userid'], 35, 1); item_remove($ir['userid'], 32, 1); item_remove($ir['userid'], 33, 1); item_remove($ir['userid'], 34, 1); echo 'You successfuly made a pizza!'; } else { echo 'You do not have the sufficient ingredients yet.'; } $h->endpage(); ?> Quote
legrolls Posted May 8, 2009 Author Posted May 8, 2009 Re: If you have an item, you can create another? Still not working, thanks anyway, everyone. Quote
Haunted Dawg Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? Lithium, your using IN() meaning that the inv_id must be in either 32,33,34 and you should use `inv_itemid` since that's what were searching. Legroll's [email protected] ill help you just pm me. Quote
Lithium Posted May 8, 2009 Posted May 8, 2009 Re: If you have an item, you can create another? HD: quite right on there... as he needs to have the items id's 32,33,34 to be able to create the item id 35... if one of those is missing... it'll return 0 rows otherwise it'll go just to a successfull pizza ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.