Page 1 of 1

newbie's question

Posted: Mon Feb 26, 2007 12:42 pm
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."'";
     .................

}

Posted: Mon Feb 26, 2007 1:12 pm
by onion2k
${"sql".$1} should work.

Why not use an array though?

Posted: Mon Feb 26, 2007 1:13 pm
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.

Posted: Mon Feb 26, 2007 1:44 pm
by qqragoon
Thanks guys!! Array worked beautifully..... :)