Having issues trying to perform a foreach within a while loop in PHP. I'm extracting build names from a database table. Those build names happen to be folder names. Within those folders is a folder (either Client or Clients) and within those are folders named after the clients business name. I want the script to show me the build name (accomplished already with an echo) and then list each folder below the build name.
$build_grab = mysql_query("SELECT b_id,b_name FROM builds", $link);
while($build_row = mysql_fetch_array($build_grab))
{
$b_id = $build_row['b_id'];
$b_name = $build_row['b_name'];
$client_dir = is_dir("/somepath/builds/$b_name/Client/");
$clients_dir = is_dir("/somepath/builds/$b_name/Clients/");
if ($client_dir == '1') {
$client_folders = explode(",", exec("ls -1 /somepath/builds/$b_name/Client/"));
} elseif ($clients_dir == '1') {
$client_folders = str_replace("\n","", explode(",", exec("ls -1 /somepath/builds/$b_name/Clients/")));
};
echo $b_name;
echo "\r\n";
foreach($client_folders as $folder)
{
echo $folder;
echo "\r\n";
}
}
Unfortunately this seems to only give me one (1) client folder name per build and it's always the last client (a-z) in the folder.
Example Output:
build-4.0.0.0
Client-f
build-4.0.0.1
Client-d
build-4.0.0.2
Client-j
What am I missing here or better yet, is there a more efficient way of doing this? Any help is greatly appreciated!