Lets say I have a mysql query:
$qry = "SELECT name,date,id,size from table";
$stmt = $db->query($qry);
while($r = $stmt->fetch()){
foreach ($r as $k => $v){
$$k = $v;
}
}
This makes sense and works fine. It gives me variables such as:
$name = 'someVal';
$date = 'someOtherVal';
Let's say now I want to do another query that may have fields that overlap. I want to prepend a "t_" to the variable name given the same format.
$qry = "SELECT name,occupation,date from otherTable";
$stmt = $db->query($qry);
while($r = $stmt->fetch()){
foreach ($r as $k => $v){
$$k = $v;
}
}
How can i have it so this query's results give me varaible names with an prepended "t_";
$t_name = 'someVal';
$t_occupation = 'someOtherVal';