I’m new to PDO and PHP, I’m wondering how I would go about defining vars from the information being pulled from my table.
I have the following:
$UID = $_GET['id'];
$sth = $conn->prepare("SELECT * FROM directory WHERE user_active != '' AND ID = '$UID'");
$sth->execute();
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo $row['First_Name'] . ' ' . $row['Surname'] . "\n";
echo '<img src="http://maps.google.com/maps/api/staticmap?center=' . $row["Location_Postcode_Last_Seen"] . '&zoom=1
4&size=200x200&maptype=roadmap&markers=color:ORANGE|label:A|' . $row["Location_Postcode_Last_Seen"] . '&sensor=true">';
echo $row["Nicknames"];
echo $row["Age"];
}
If I try adding:
var $name = echo $row['First_Name'] . ' ' . $row['Surname'];
within my while loop the code fails to output anything to my browser.
assigning a variable is done like this,
and echo/displaying it, should be done like,
the while loop, as given in the question should work fine, displaying all that you are trying to
echoout, as long as those keys exist in the resultset.Edit: (as per comment)
Note: Variables need to be assigned only if they need to be accessed multiple times.