Adding to my page, not sure if placement of code matters?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Adding to my page, not sure if placement of code matters?

Post by cdoyle »

I'm redoing my medical ward page, to allow other players to pay other players medical bills.

So I'm redoing the page, and trying to use what I've learned from my other threads, and using If/ELSE IF's.
one problem I'm running into is a check to make sure the player has enough gold to get the other player out.

When the page first loads, I have a variable named $heal which is this

Code: Select all

 
$heal = round(($alldead['dead_time_remaining']-$currenttime)*100);
 
that calculates how much is owed for each player in the hospital.

So now, I'm trying to use that to make sure the player paying the bills has enough, but it's not working. I think it's because of where I have that variable defined. I've tried to echo $heal in my if statement, and nothing appears.

but I've also tried moving it, but then it doesn't calculate the amount correctly anymore for each player.

I've attached my original medical ward as reference, and here is the code I'm trying to change it too.

Anyone know what I'm doing wrong?

I've tried changed my IF to ($player->gold < 500000) as a test, and it said I didn't have enough gold.
So I think the IF is OK??

Code: Select all

 
<?php
   
    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");
 
?>
 
Attachments
medical_ward.zip
(845 Bytes) Downloaded 40 times
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Adding to my page, not sure if placement of code matters?

Post by cdoyle »

Does it matter where my queries are placed within the page, or can I call to them from anywhere within the page?
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Adding to my page, not sure if placement of code matters?

Post by cdoyle »

anyone have any ideas what I'm doing wrong?
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Adding to my page, not sure if placement of code matters?

Post by cdoyle »

Anyone?

I haven't been able to figure out how to make this work, I need to use $heal in a couple places.
It's used once to determine how much is needed to pay the bills, and then used again to verify that the player has enough to buy them out.

but I can't seem to make it work in both places.
Post Reply