468,315 Members | 1,456 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

variable variables question

I'm a bit unclear on the variable variables section of the PHP manual.
Here's what I want to accomplish:

$01_varA="foo"
$02_varA="bar"
$03_varB="boo"
$04_varB="far"

"01" through "04" are being gathered via mysql query as "id" in the
example.
I want to do this.....

$sql_query=("SELECT * from database");

while ($sql_array=($sql_query)){
echo $sql_array["id"] . "_varA";
echo $sql_array["id"] . "_varB";
}

....so that it will echo the values of $01_varA, $02_varA, $03_varB and
$04_varB in no particular order.

Feb 10 '06 #1
3 974
print ${$sql_array['id'] . '_varA'};

Feb 10 '06 #2
d
"Dave" <gw*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm a bit unclear on the variable variables section of the PHP manual.
Here's what I want to accomplish:

$01_varA="foo"
$02_varA="bar"
$03_varB="boo"
$04_varB="far"

"01" through "04" are being gathered via mysql query as "id" in the
example.
I want to do this.....

$sql_query=("SELECT * from database");

while ($sql_array=($sql_query)){
echo $sql_array["id"] . "_varA";
echo $sql_array["id"] . "_varB";
}

...so that it will echo the values of $01_varA, $02_varA, $03_varB and
$04_varB in no particular order.


Any reason you're not using arrays? :)
Feb 10 '06 #3
>print ${$sql_array['id'] . '_varA'};

This did the trick! Thanks a ton!

Feb 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Grant Wagner | last post: by
134 posts views Thread by James A. Donald | last post: by
4 posts views Thread by John Kraft | last post: by
23 posts views Thread by Russ Chinoy | last post: by
148 posts views Thread by onkar | last post: by
53 posts views Thread by fdmfdmfdm | last post: by
37 posts views Thread by minkoo.seo | last post: by
112 posts views Thread by istillshine | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.