0

I have this problem, I want to use opendir with this array of directories, it is possible? with a fixed url I can read files with readdir. But I dont know what to do with multiple directories...
Creating the array:

$results = mysqli_query($connecDB,"SELECT * FROM brands WHERE 1 IN (php, ruby, java) ORDER BY id ASC");

//select all records with value "1" in different columns "php ruby java".
// The value "1" indicates a folder created named $id in php, ruby and/or java folder

$resultsArray = array();

while($row = mysqli_fetch_assoc($results)){
    if($row['php'] == 1) {
        $resultsArray['php'][] = $row['id'];
    }
    if($row['java'] == 1) {
        $resultsArray['java'][] = $row['id'];
    }
    if($row['ruby'] == 1) {
        $resultsArray['ruby'][] = $row['id'];
    }
}

foreach($resultsArray as $language => $array){
    echo "url/" . $language . "/" . $row['id'] . "<br>";
}

And the output example:
url/php/1/
url/java/1/

url/php/2/
url/ruby/2/
url/java/2/

url/php/3/

url/php/4/
url/ruby/4/
etc

thank you very much

santyas
  • 96
  • 1
  • 2
  • 12
  • I actually dont understand, what is working wrong and what do you want to achieve? – JTC Aug 20 '13 at 14:56
  • @JTC I dont know where to locate the `opendir` to read all the directories generated. I'm trying in the `foreach` but doesnt work. Thank you – santyas Aug 20 '13 at 15:02

2 Answers2

1
foreach($resultsArray as $language => $array){
    foreach(array_slice(glob('work/'.$language.'/'.$rowtest['id'].'/*.jpg'),0,1) as $image){    
        echo $image . "<br />";
    }
}
santyas
  • 96
  • 1
  • 2
  • 12
0

You can read from the directories one after the other in your foreach-loop. What is the problem exactly?

tholu
  • 1,150
  • 2
  • 10
  • 24
  • that should be comment not answer – JTC Aug 20 '13 at 14:58
  • @tholu I can print the directories using variables, but my code doesnt read, not using opendir yet. I dont know where to locate the opendir and readdir. – santyas Aug 20 '13 at 15:05
  • I still don't understand what you are really trying to accomplish, perhaps you can extend the question accordingly. Please also take a look at the answer from santyas. – tholu Aug 20 '13 at 19:50