I am running SQL code to pull data from a database. I want to assign the data's obtained from the database into a variable useable by php.
Here is my code:
$result = $db -> query("SELECT * FROM " . $table . " WHERE Ticker = " . "'META'");
$test = $result->fetch(PDO::FETCH_OBJ);
print_r($test);
When I print out the $test variable using $print_r I get:
stdClass Object ( [id] => 12 [Ticker] => META [Price] => 163.26 [% Change] => 16.326 )
I want to pull the "Price" and "% Change" into separate variables I can use later in my PHP code.
I am having trouble. Any tips?
CodePudding user response:
First, you cant start a variable name with symbols, and the variable name must be without space too.
change % Change
to change_percent
Answer: In your case $price = $test->Price;
must be work.