Custer Posted July 23, 2007 Share Posted July 23, 2007 Alright, on one of my pages, I'm displaying the production stats of my users, such as they are making 100 Lumber an hour, etc..,etc...and I've coded this just fine and it's working great, through a loop. But I want to add an if statement that checks the user if he has enough resources in order for the production to occur (ie, he turns 25 logs into 100 lumber an hour, but my user has 0 logs, so no production occurs), and if he doesn't, I don't want that part of the production to display. So let's say: User1 0 logs 100 stone 1 sawmill (turns 50 logs into 100 lumber) -50 logs/hour -25 stone/hour +100 lumber/hour Because he doesn't have enough logs, I don't want the -50 logs/hour or the +100 lumber/hour to show. Here's the code for the that production table: //Begin Production Table $ubuildingsb = ("SELECT * FROM user_buildings WHERE user_id = $userid"); $resultd = mysql_query( $ubuildingsb ) or die(mysql_error()); $infod = mysql_fetch_assoc( $resultd ); $buildingidb = $infod['building_id']; $input = ("SELECT * FROM buildings WHERE building_id = $buildingid AND cost_type = '1'"); $resultin = mysql_query( $input ) or die(mysql_error()); $infoe = mysql_fetch_assoc( $resultin ); $restype = $infoe['cost_restype']; $inputamount = $infoe['cost_amount']; $resources = ("SELECT name FROM resources WHERE id = $restype"); $resultre = mysql_query( $resources ) or die(mysql_error()); $output = ("SELECT * FROM buildings WHERE building_id = $buildingid AND cost_type = '2'"); $resultout = mysql_query( $output ) or die(mysql_error()); $outinfo = mysql_fetch_assoc( $resultout ); $restypeout = $outinfo['cost_restype']; $outputamount = $outinfo['cost_amount']; $resourcesb = ("SELECT name FROM resources WHERE id = $restypeout"); $resultout = mysql_query( $resourcesb ) or die(mysql_error()); echo ("<center><h1 style='font-size:150%'>Production</h1></center>"); echo ("<center><table>"); echo "<tr><th>Input:</th>"; while($infof = mysql_fetch_assoc( $resultre )) { echo "<tr><td> - ".$inputamount ." ".$infof['name']." ,</td></tr> "; } echo "<tr><th>Output:</th>"; while($outinfob = mysql_fetch_assoc( $resultout )) { echo "<tr><td> + ".$outputamount ." ".$outinfob['name']." ,</td></tr> "; } echo ("</table></center>"); Anybody willing to help me out? Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 23, 2007 Share Posted July 23, 2007 while($outinfob = mysql_fetch_assoc( $resultout )) { if($outputamount>100){ echo "<tr><td> + ".$outputamount ." ".$outinfob['name']." ,</td></tr> "; } } and use an else that correct Quote Link to comment Share on other sites More sharing options...
Custer Posted July 24, 2007 Author Share Posted July 24, 2007 See, it's definitely not that simple. Because above the code, I'm laying out all of the users resources and buildings (working fine!), and I need to check off of his actual amount, not the buildings output amount. And there are like 50 buildings in the game, so I'm going to have to call off of that building's id, and I could probably come up with a good if statement, but it'd take me all night or longer. :s Quote Link to comment Share on other sites More sharing options...
Custer Posted July 24, 2007 Author Share Posted July 24, 2007 Sorry for the double post. I got to thinking, and you're either going to have to have a really big loop containing the if, and then the two smaller loops, just because then, you'll want to echo the corresponding data together, so that the 50+ and -50 go together... Quote Link to comment Share on other sites More sharing options...
suttercain Posted July 24, 2007 Share Posted July 24, 2007 Is this Age of Empires III? Quote Link to comment Share on other sites More sharing options...
Custer Posted July 24, 2007 Author Share Posted July 24, 2007 No, it's not... An industry game... Quote Link to comment Share on other sites More sharing options...
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.