Note that there are some explanatory texts on larger screens.

plurals
  1. PORepeat a PHP readdir code
    primarykey
    data
    text
    <p>Maybe it's a dumb question, but I wasn't able to solve it myself.</p> <p>I have the following code:</p> <pre><code>&lt;?php $path = "galeria01"; $dir_handle = @opendir($path) or die("Not found: $path"); list_dir($dir_handle,$path); function list_dir($dir_handle,$path) { global $div; $div = 001; global $zindex; $zindex = 200; global $margem; $margem = 114; while ((($file = readdir($dir_handle)) !== false)) { if ($file != "." &amp;&amp; $file != ".." ) { echo PHP_EOL . '&lt;div id="'; echo str_pad($div, 3, 0, STR_PAD_LEFT); echo '" style="position:absolute;left:'; echo $margem; echo 'px;z-index:'; echo $zindex; echo '"&gt;&lt;img src="galeria01/'; echo $file; echo '" width="675" height="450" /&gt;&lt;/div&gt;'; echo'&lt;span class="clear"&gt;&lt;/span&gt;'; $div++; $zindex--; $margem = $margem - 675; } } } closedir($dir_handle); ?&gt; </code></pre> <p>As you can see, it read all files in a folder, and generates the following code:</p> <pre><code>&lt;div id="001" style="position:absolute;left:114px;z-index:200"&gt;&lt;img src="001.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt; &lt;div id="002" style="position:absolute;left:-561px;z-index:199"&gt;&lt;img src="002.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt; &lt;div id="003" style="position:absolute;left:-1236px;z-index:198"&gt;&lt;img src="003.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt; &lt;div id="004" style="position:absolute;left:-1911px;z-index:197"&gt;&lt;img src="004.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt;&lt;/div&gt; </code></pre> <p>I just need to re-run the code a few times and generate all those dinamically generated divs, in the same order again, but ALWAYS decreasing the left margin and z-index values, like this:</p> <pre><code> &lt;div id="001" style="position:absolute;left:114px;z-index:200"&gt;&lt;img src="001.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt; (...) &lt;div id="004" style="position:absolute;left:-1911px;z-index:197"&gt;&lt;img src="004.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt;&lt;/div&gt; &lt;div id="001" style="position:absolute;left:-2586px;z-index:196"&gt;&lt;img src="001.jpg" width="675" height="450" /&gt;&lt;/div&gt;&lt;span class="clear"&gt;&lt;/span&gt; (...) </code></pre> <p>How do I do that?</p> <p>I hope it's simple and that you can kindly help me.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload