cdoyle Posted May 20, 2008 Share Posted May 20, 2008 Hi, I have made a query for my game, if a user is killed in the game it insert them into a 'medical_ward' table. After a battle, this query is ran $db->query("INSERT INTO medical_ward (playerdead_ID, Killed_By_ID, Weapon_Used_ID, Time_Left) VALUES ('$player->id', '$enemy->id', '$enemy2[id]', '$enemy2[hospital_time]' )"); this all works but has one little glitch. the hospital time is determined by what weapon the winner used, but what I found is. If the winner did not have any weapons equipped it insert them into the database with 0 minutes. I tried changing the default value of this field to a set number, but the query just overwrites it to 0. How could I go and make it so if the winner has no weapons, it still inserts the loser into the table for a default time? say 5 minutes? Link to comment https://forums.phpfreaks.com/topic/106509-need-help-with-insert-query/ Share on other sites More sharing options...
947740 Posted May 20, 2008 Share Posted May 20, 2008 Just do an if statement. <?php if($noweapon == "true") { $enemy2[hospital_time] = "5"; } else { $enemy2[hospital_time] = $someothervar; } ?> Link to comment https://forums.phpfreaks.com/topic/106509-need-help-with-insert-query/#findComment-545965 Share on other sites More sharing options...
micmania1 Posted May 20, 2008 Share Posted May 20, 2008 <?php if ($enemy2['hospital_time'] == 0) { $enemy2['hospital_time'] = $min_hospital_time; } Link to comment https://forums.phpfreaks.com/topic/106509-need-help-with-insert-query/#findComment-545968 Share on other sites More sharing options...
cdoyle Posted May 20, 2008 Author Share Posted May 20, 2008 <?php if ($enemy2['hospital_time'] == 0) { $enemy2['hospital_time'] = $min_hospital_time; } I thought an IF statement would be what I needed to do. Where would I put this tho? and $min_hospital_time I would just do something like this within my page right? $min_hospital_time = 5; Link to comment https://forums.phpfreaks.com/topic/106509-need-help-with-insert-query/#findComment-545986 Share on other sites More sharing options...
947740 Posted May 21, 2008 Share Posted May 21, 2008 You would have to put that insert statment before the query. As long as you put it before, there should not be any problems. As far as and $min_hospital_time I would just do something like this within my page right? $min_hospital_time = 5; it depends on how dynamic you want it. If you want there to be variance in hospital times, you could use more if statements, or a switch statement (I think). Link to comment https://forums.phpfreaks.com/topic/106509-need-help-with-insert-query/#findComment-546485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.