Jump to content

Need help with insert query


cdoyle

Recommended Posts

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

<?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; 

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.