Jump to content

Recommended Posts

how would i ouput these echo's instead of echos.

 

<?php
$energyreduce = ($player->energy);
//UPDATE STRENGTH.
if ($_POST['full_strength'])
{
if($player->energy + $energy1 < 1 )
    {
        echo"<br>You dont have any energy left";
        echo"<br><br><a href=\"gym.php\">Back</a>";
	exit;
        
    }
    
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $player->energy, ($player->awake - $awakeloss) < 0 ? 0 : $player->awake - $awakeloss, $player->strength + $statgain, $player->total + $statgain, $player->id ));

echo "<br>You gained " . number_format($statgain, 2, ".", ",") . " Strength";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/160551-outputting-instead-of-echoing/
Share on other sites

Echoing is outputting? Do you mean making it only output a single string? If so then you can just build it all into one string. Instead of echoing something just add it a collective output string, that you'll echo at the end.

 

$string .= "stuff";
$string .= ", more stuff..";

echo $string;

Output:  stuff, more stuff..

well for example after that code i have this..

 

 

<form method='post'><br>
    <table width='80%' align='center'>
        
        <tr>
            <td align='center'><input type='submit' name='full_strength' value='All Strength'></td>
            <td align='center'><input type='submit' name='full_defense' value='All Defense'></td>
            <td align='center'><input type='submit' name='full_speed' value='All Speed'></td>
            <td rowspan='2' width='10'>
                 

            </td>
            <td rowspan='2' width='100'>
                <b>Refill:</b><br><br>
                <a href='refillenergy2.php'>
                Energy</a><br><br>
                <a href='refillawake2.php'>
                Awake</a><br>
            </td>
        </tr>

        <tr>
            <td align='center'> </td>
            <td align='center'><input type='submit' name='train' value='Train'></td>
            <td align='center'> </td>
        </tr>
        </table>
    </form>
</tr>
</table></div></div>
<div class="g_content"><h3 style="text-align: left">  Attributes</h3><div class="g_text">    <table width='100%'>
<tr>
    <td width='15%'>Strength:</td>
    <td width='35%'><?= $english_format_number = number_format($player->strength);?></td>
    <td width='15%'>Defense:</td>
    <td width='35%'><?= $english_format_number = number_format($player->defense);?></td>
</tr>
<tr>
    <td width='15%'>Speed:</td>
    <td width='35%'><?= $english_format_number = number_format($player->speed);?></td>
    <td width='15%'>Total:</td>
    <td width='35%'><?= $english_format_number = number_format($player->total);?></td>

</tr>
</table></div></div>

 

the echo (output) shows the amount a value in the database has been added....

 

the following shows a value in the database..

<?= $english_format_number = number_format($player->total);?>

 

however when i run the form and get the echo/output i have to refresh the page before the a $player->total value is updated.

 

no, i cant see how thats happening.

 

here is the entire page..

 

 

<?php
include("lib.php");
define("PAGENAME", "Gym");
$player = check_user($secret_key, $db);

//UPDATE STRENGTH.
if ($_POST['full_strength'])
{
if($player->energy + $energy1 < 1 )
    {

	$output .= "<br>You dont have any energy left";
	$output .= "<br><br><a href=\"gym3.php\">Back</a>";
	exit; 
    }
    
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $player->energy, ($player->awake - $awakeloss) < 0 ? 0 : $player->awake - $awakeloss, $player->strength + $statgain, $player->total + $statgain, $player->id ));
$output .= "<br>You gained " . number_format($statgain, 2, ".", ",") . " Strength";
}

$energyreduce = ($player->energy);
//UPDATE DEFENSE.
if ($_POST['full_defense'])
{
if($player->energy + $energy1 < 1 )
    {
	$output .= "<br>You dont have any energy left";
	$output .= "<br><br><a href=\"gym3.php\">Back</a>";
	exit;
        
    }
    
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `defense`=?, `total`=? where `id`=?", array($player->energy - $player->energy, ($player->awake - $awakeloss) < 0 ? 0 : $player->awake - $awakeloss, $player->defense + $statgain, $player->total + $statgain, $player->id ));

$output .= "<br>You gained " . number_format($statgain, 2, ".", ",") . " Defense";

}

$energyreduce = ($player['energy']);
// UPDATE SPEED.
if ($_POST['full_speed'])
{
    if($player->energy + $energy1 < 1 )
    {
	$output .= "<br>You dont have any energy left";
	$output .= "<br><br><a href=\"gym3.php\">Back</a>";
        exit;
    }
    
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `speed`=?, `total`=? where `id`=?", array($player->energy - $player->energy, ($player->awake - $awakeloss) < 0 ? 0 : $player->awake - $awakeloss, $player->speed + $statgain, $player->total + $statgain, $player->id ));
$output .= "<br>You gained " . number_format($statgain, 2, ".", ",") . " Speed";
}

if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] > $player->energy)
{
$output .= "<br>You dont have any energy left";
$output .= "<br><br><a href=\"gym3.php\">Back</a>";
exit;
    
}

if ($_POST['energy_str'])
{ 
    if($player->energy < 1 || $_POST['energy_str'] > $player->energy)
    {
	$output .= "<br>You dont have any energy left";
	$output .= "<br><br><a href=\"gym3.php\">Back</a>";
        exit;
    }
    
else if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] <= $player->energy)
{
$energyloss = ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd']); 
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `strength`=?, `total`=? where `id`=?", array($player->energy - $energyloss, ($player->awake - $awakeloss2) < 0 ? 0 : $player->awake - $awakeloss2, $player->strength + $statgain2, $player->total + $statgain5, $player->id ));
$output .= "<br>You trained\n" . $_POST['energy_str'] . "\ntimes and You gained " . number_format($statgain2, 2, ".", ",") . " Strength<br>";
}
}

if ($_POST['energy_def'])
{
    if($player->energy < 1 || $_POST['energy_def'] > $player->energy)
    {
	$output .= "<br>You dont have any energy left";
	$output .= "<br><br><a href=\"gym3.php\">Back</a>";
        exit;
    }
    
else if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] <= $player->energy)
{
$energyloss = ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd']);     
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `defense`=?, `total`=? where `id`=?", array($player->energy - $energyloss, ($player->awake - $awakeloss3) < 0 ? 0 : $player->awake - $awakeloss3, $player->defense + $statgain3, $player->total + $statgain5, $player->id ));
$output .= "<br>You trained\n" . $_POST['energy_def'] . "\ntimes and You gained " . number_format($statgain3, 2, ".", ",") . " Defense<br>" ;
}
}

if ($_POST['energy_spd'])
{
    if($player->energy < 1 || $_POST['energy_spd'] > $player->energy)
    {
	$output .= "<br>You dont have any energy left";
	$output .= "<br><br><a href=\"gym3.php\">Back</a>";
        exit;
    }

else if ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd'] <= $player->energy)
{
$energyloss = ($_POST['energy_str'] + $_POST['energy_def'] + $_POST['energy_spd']);     
$query = $db->execute("update `players` set `energy`=?, `awake`=?, `speed`=?, `total`=? where `id`=?", array($player->energy - $energyloss, ($player->awake - $awakeloss4) < 0 ? 0 : $player->awake - $awakeloss4, $player->speed + $statgain4, $player->total + $statgain5, $player->id ));
$output .= "<br>You trained\n" . $_POST['energy_spd'] . "\ntimes and You gained " . number_format($statgain4, 2, ".", ",") . " Speed<br>" ;
}
}
include("templates/private_header3.php");
?>

<html>
<head>
<title>MafiaKiller</title>
<link rel="stylesheet" href="/css/style.css" type="text/css" media="all" />
</head>
<body alink="#cc9900" vlink="#cc9900" link="#cc9900">
    </div>
    </div>
    <div id="left_c"><div class="g_content"><h3 style="text-align: left">  Gym</h3><div class="g_text">    <table width='100%'>
<tr>
<?php echo $output; ?>
    <form method='post'><br>
    <table width='80%' align='center'>
        
        <tr>
            <td align='center'><input type='submit' name='full_strength' value='All Strength'></td>
            <td align='center'><input type='submit' name='full_defense' value='All Defense'></td>
            <td align='center'><input type='submit' name='full_speed' value='All Speed'></td>
            <td rowspan='2' width='10'>
                 

            </td>
            <td rowspan='2' width='100'>
                <b>Refill:</b><br><br>
                <a href='refillenergy2.php'>
                Energy</a><br><br>
                <a href='refillawake2.php'>
                Awake</a><br>
            </td>
        </tr>

        <tr>
            <td align='center'> </td>
            <td align='center'><input type='submit' name='train' value='Train'></td>
            <td align='center'> </td>
        </tr>
        </table>
    </form>
</tr>
</table></div></div>
<div class="g_content"><h3 style="text-align: left">  Attributes</h3><div class="g_text">    <table width='100%'>
<tr>
    <td width='15%'>Strength:</td>
    <td width='35%'><?= $english_format_number = number_format($player->strength);?></td>
    <td width='15%'>Defense:</td>
    <td width='35%'><?= $english_format_number = number_format($player->defense);?></td>
</tr>
<tr>
    <td width='15%'>Speed:</td>
    <td width='35%'><?= $english_format_number = number_format($player->speed);?></td>
    <td width='15%'>Total:</td>
    <td width='35%'><?= $english_format_number = number_format($player->total);?></td>

</tr>
</table></div></div>

You're updating the db values, but you're not updating the player object's values at the same time.  Changes in the db aren't magically transferred to the player.  So, the changes are staggered as you don't refresh the player object until the entire page is reloaded.

so what do you suggest that i do?

 

Well, you need to update the $player before attempting to show that it's changed.  What I'd do is simply modify the $player with whatever changes (if any) were made, then display those changes.  If any changes were made, then I'd update the db at the end of the script.

Thats kinda silly isnt it.

Obviously yer creating a lot more work than is needed, if you would have taken the advice.

Which makes perfect sense

 

But now yer doing all these extravagent tricks, which dont work.

 

So Q? Why ask for advice/help if yer intent on sticking with your way?

 

I dont know about the rest, but that seems kinda rude...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.