Jump to content

placement of code not right?


cdoyle

Recommended Posts

Hi,

 

I'm trying to add to one of my pages, the ability for users to buy out hospital time of other players.

I've been trying to use what I've learned from my other posts, and trying to use more If/else If's to get all my checks done.

 

I've run into a problem where one of my checks isn't working, and I think it's because of where my code is placed.

 

here is what I have so far,

The check I'm having problems with is seeing if the player has enough gold.

$heal is used later on to display how much is owed, but I was trying to use it here to determine if the player has enough cash.

 

I've tried to echo it within the if, and nothing appears.  So I'm thinking it's not appearing because it doesn't run that until later in the code when it display the main table with everyone who is dead.

 

I've tried to move $heal up to the beginning of the code, but then it doesn't seem to work anymore.  I get negative numbers etc.

 

Here is my code so far,  can anyone help me tweak it to make it work?

 

include("lib.php");
    $player = check_user($secret_key, $db);
    include("templates/private_header.php");
    $currenttime = time();
    $getdead = $db->execute("SELECT b.*, d.username AS killedby, c.name as weapon FROM players d
                                                Inner JOIN players b ON b.Killed_by_ID = d.id
                                                Inner JOIN blueprint_items c ON b.Weapon_Used_ID = c.id
                                                Where b.dead_time_remaining > $currenttime
                                                ORDER BY dead_time_remaining");  
    $totaldead = $getdead->recordcount(); 
    

    if ($_GET['act'] == "go") {
        
        $getdead = $db->execute("SELECT `username`, `dead_time_remaining`, `id` FROM `players` where `id`=?", array($_GET['id']));
        $getdeadplayer = $getdead->fetchrow();  //get dead player from link.
        // check that patient is not self
   
        if ($player->id == $getdeadplayer['id'])
        {
            echo "You cannot buy yourself out of the hospital, you must wait it out or use items from your inventory";
        }
        //check if player has enough gold
        else if ($player->gold < $heal)
        {
          
            echo "You don't have enough cash to pay this players medical bills";
            echo $heal;
        }
    }

   else
{

    
    echo "<table width=\"100%\" border=\"1\">";
    echo "<tr>" ;
    echo "<td width=\"55%\"><strong>Patient</strong></td>";
    echo "<td width=\"13%\"><div align=\"center\"><strong>Time Left</strong></div></td>";
    echo "<td width=\"32%\"><div align=\"center\"><strong>Pay Patients Bills</strong></div></td></tr>";
    
       
    while($alldead = $getdead->fetchrow())
        
    {
        echo "<tr><td>";
        echo $alldead['username'] . "\n";
        echo "was killed by \n" . $alldead['killedby'] . "'s\n"  ;
        echo $alldead[weapon];	
        echo "</td>\n";
        echo "<td <div align=\"center\">" . round(($alldead['dead_time_remaining']-$currenttime)/60);
        echo "</td>";
        $heal = round(($alldead['dead_time_remaining']-$currenttime)*100);
        echo "<td><div align=\"center\">$". number_format($heal) . "<br>";
        echo "<a href=\"medical_ward.php?act=go&id=". $alldead['id'] ."\">Pay Bill</a></td>";
    }
    echo "</table>\n<p></p>";
    echo "<b>Total Players who got the turds beat out of them.\n". $totaldead;
   
  
}
    include("templates/private_footer.php");

?>

Link to comment
https://forums.phpfreaks.com/topic/124410-placement-of-code-not-right/
Share on other sites

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.