Page 1 of 1

Dynamic Var in array

Posted: Sun Sep 16, 2012 10:15 am
by janvier123
[syntax=php]
$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>";
}

[/syntax]


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

Re: Dynamic Var in array [Fast response plz]

Posted: Sun Sep 16, 2012 12:21 pm
by Helx
[syntax=php]<?php
$data = $ur_sql_stuff['here']
$data2 = $ur_sql_stuff['there']

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

echo $array[0];
echo $array[1];
?>[/syntax]
?

Re: Dynamic Var in array

Posted: Sun Sep 16, 2012 9:13 pm
by jacek
You can combine variables...

[syntax=php]$data["achie_{$achie['id']}"][/syntax]
The string in the array key is just like any other string.

Re: Dynamic Var in array

Posted: Tue Sep 18, 2012 7:03 am
by janvier123
Thx for that :)