Dynamic Var in array

Ask about a PHP problem here.
Post Reply
janvier123
Posts: 23
Joined: Tue Apr 17, 2012 6:25 am

Dynamic Var in array

Post by janvier123 »

$tpl = "";
$query2 = $dekaron->SQLquery("SELECT * FROM character.dbo.user_character_achievements WHERE character_no = 'C12090560000000127' ");
$data = $dekaron->SQLfetchArray($query2);

$query3 = $dekaron->SQLquery("SELECT * FROM account.dbo.user_achievements ");
while ($achie = $dekaron->SQLfetchArray($query3))
{
	$id = "achid_".$achie['id'];
	$done = $data[$id];
	$tpl .= "<tr><td><img src='achimg.php?done=".$done."&triggers=".$achie['triggers']."&finished_triggers=".$done."&name=".urlencode($achie['name'])."&desc=".urlencode($achie['desc'])."&id=".$achie['id']."'></td></tr>";
}


Ok code may seem crappy but i CANNOT change it


here is what the prob is

I need to have a value from the database $data['achie_xx']
the XX refers to $achie['id'], so my question is how to i get $data['achie_1'], $data['achie_3'],$data['achie_9'] ?


thx
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: Dynamic Var in array [Fast response plz]

Post by Helx »

<?php
$data = $ur_sql_stuff['here']
$data2 = $ur_sql_stuff['there']

$array = array('name' => $data, 'name2' => $data2);

echo $array[0];
echo $array[1];
?>
?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Dynamic Var in array

Post by jacek »

You can combine variables...
$data["achie_{$achie['id']}"]
The string in the array key is just like any other string.
Image
janvier123
Posts: 23
Joined: Tue Apr 17, 2012 6:25 am

Re: Dynamic Var in array

Post by janvier123 »

Thx for that :)
Post Reply