4x? random image table php
<p>so im trying to create an image gallery that displays a random image in each cell in a 4 column table and automaticly extends as more images are added to the folder and trying to set it so that every time it load it randomizes the images. right it just reads the images in order and on each row it starts over instead of continuing on though the images.
my code:</p>

<pre><code>    $file = null;

    $fileList = glob("./upload/*.*");
    //create table tag
    echo '&lt;table border=1 cellspacing=1 cellpadding=2 width=100%&gt;'; 
    //create tr tag
    echo '&lt;tr&gt;';  
    # Print each file
    echo "Files found:"; foreach($fileList as $file) {   
    echo " - ". $file;   
    echo '&lt;td width="25%"&gt;&lt;img src="' . $file . '" width="100%" /&gt;&lt;/td&gt;'; }

    echo '&lt;/tr&gt;'; 
    echo '&lt;/table&gt;';
</code></pre>

<p>that was my first try and it just create a single row
my second attempt:</p>

<pre><code>    //create table
    echo '&lt;table border=1 cellspacing=1 cellpadding=2 width=100%&gt;';
    echo '&lt;tr&gt;';

    $x = 1;
    $y = 1;

    //  Display  the  results 
    do { 

    do {
    foreach($fileList as $file) 
    echo '&lt;td width="25%"&gt;&lt;img src="' . $file . '" width="100%" /&gt;&lt;/td&gt;';
    $x = $x +1;
    $y = $y +1;
    }
    while ($x &lt;= 3);

    do {
    foreach($fileList as $file) 
    echo '&lt;td width="25%"&gt;&lt;img src="' . $file . '" width="100%" /&gt;&lt;/td&gt;';
    echo '&lt;/tr&gt;';
    echo '&lt;tr&gt;';
    $x = $x - 4;
    $y = $y +1; 
}
    while ($x = 5);
    } 
    while ($y &lt;= 20);

    echo '&lt;/tr&gt;';   
    echo '&lt;/table&gt;';
</code></pre>

<p>this time it just starts over on every row and create way to many rows</p>
