newbie's question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qqragoon
Forum Newbie
Posts: 17
Joined: Wed Nov 15, 2006 6:17 pm

newbie's question

Post by qqragoon »

Is there a way to combine two variable names? I would like to have $sql1,$sql2 .... assign to different string by using single FOR statement. please see the following code. I know "$sql.$i" is wrong, then how do i put $i into the variable $sql? another way? sorry for the dumb question.....

Code: Select all

<?php 

for ($i=0;$i<5;$i++) {
     $sql.$i = "select * from temp where col = '".$i."'";
     .................

}
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

${"sql".$1} should work.

Why not use an array though?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

As onion2k pointed out, variable variables is the solution you have requested, however he also brought up the question of using arrays. I would like to echo this as well.
qqragoon
Forum Newbie
Posts: 17
Joined: Wed Nov 15, 2006 6:17 pm

Post by qqragoon »

Thanks guys!! Array worked beautifully..... :)
Post Reply