Q:

Getting values out of mysql database and putting one of the 4 values into a php variable

I am making a very basic game in php for school.  In this game you can buy money and troops (for now).  When you press the money button you get $100 and if you press the troops button you can buy the troops for $400.  
Now here is my problem.  If you have too little money you can't buy troops, that's logical.  What I want to do is display how much money you are missing.  I already have a database with the columns money and troops.  So what I need to do is place the value for money into a php variable and subtract that from the $400 dollars that is needed to get 1 troop. 
How can I place that value into a php variable?  Thanks in advance.  

A:

Here below is an example of what you can do.  Don't just Copy paste it because it wont work, be sure you UNDERSTAND what this is and what it does before you proceed.  
<? php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " .  $conn->connect_error);
} 

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " .  $row["id"]. " -  Name: " .  $row["firstname"]. " " .  $row["lastname"]. " <br>";
    }
} else {
    echo "0 results";
}
$conn->close();
? >

This comes from the W3Schools page for PHP/Mysql.  
You might wanna read up on those ;-) 
URL : http://www.w3schools.com/php/php_mysql_select.asp

