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!
<?php
$enemy = "150";
if ( $enemy < "0" ) {
echo "you have killed the monster<br />";
}
echo "monsters HP" . "$enemy <br />";
$char = "100";
if ($char < "0"){
echo "you have died game over!<br />";
}
echo "your HP" . "$char<br />";
$attack = $enemy - "10";
$focus = $char - "5";
?>
<button type="button" id="$attack">attack</button>
<button type="button" id="$focus">focus</button>
My problem is Is php the best for this? If not I can learn JavaScript as well?. how can i make this work and be refreshed to the user?
I am sorry, I really feel bad asking this.
Sure, you can do it with only PHP. It involves a page refresh so the user might not be too happy about that.
Something better would be PHP+AJAX. Button click -> send information to server -> receive information about what happened -> display it to the user. No page refreshes. The backend will look pretty much the same, though - you're still outputting the result of the action, but it won't be coupled to the rest of the page HTML.
The best is that you study both of them, Javascripts gives pleasure to users in a way of interactively doing something without most of the page load. Then use php to verify the actions being made.