2013-11-03 05:30
浏览 115


Is it possible to call functions within for loops? I have a number of databases that are exactly the same, I would like to use a for loop to set up the connections one at a time (35 databases). I am having trouble with getting php to declare a function with a variable in the name.

for ($i = 1; $i <= 35; $i++) 
    echo "<br><br>DB $i";
    $connection$j = prodDB$i();
    $getFromDB = "select URL, count(id) as counts from ProductList GROUP BY URL";
    $NamesReturned = mysqli_query($connection$j,$getFromDB) or die("Can't execute query GFNFDB.<br><br>$getFromDB<br><br>");
    while ($ret=mysqli_fetch_array($NamesReturned))
        echo "<br>$DB$icounts -- $URL";
    echo "<br>$DB$icounts";
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzheyo2617
    douzheyo2617 2013-11-03 05:37

    I think what you need to use is braces. Eg: $connection{$j}=prodDB{$i}();

    I could be wrong though. It has been a long time since i did it.

    You might be better using arrays and/or passing parameters to your functions. Eg:


    点赞 评论