Hi, I'm a new member and I would like some help, if possible. I am trying to make a PHP script that will turn X lines of image urls and display 3 images in a row with their array key in the row below, showing up in a HTML table.

The output i'm trying to achieve is

<table>
<tr><td>img1</td><td>img2</td><td>img3</td></tr>
<tr><td>0</td><td>1</td><td>2</td></tr>
<tr><td>img4</td><td>img5</td><td>img6</td></tr>
<tr><td>3</td><td>4</td><td>5</td></tr>
</table>

This is what I have so far: I can input my image urls with a space between and display the array key and value.

form.html

<form action="ariel.php" method="post">
<textarea cols="60" rows="10" name="images"> </textarea> 
<br />
<input type="submit" value="submit" />
</form>

ariel.php


<?php 

$array = explode (' ', $_POST['images']);

foreach($array as $key => $value) 
{
echo "$key $array <br />";
}


?>

Any help is greatly appreciated.

    Let's do it one step at a time.
    1. change the echo to echo $key instead of $array.
    2. instead of echo inside the loop, use two variables.
    One: you concatenate the image names with spaces into it.
    Two: you concatenate the $key values (separated with spaces into it).

      did I do that right?

      <?php 
      
      $array = explode (' ', $_POST['images']);
      
      foreach($array as $key => $value) 
      {
      echo "$key" . " $array";
      }
      
      
      ?>
      
        <?php 
        
        $array = explode (' ', $_POST['images']);
        $im='';
        $k='';
        foreach($array as $key => $value) 
        {
           $im.=' '.$value;
           $k.=' '.$key;
        }
        
        echo $im.'<br />',$k;

        Now, you have to play with that to make it right.

          Hi, thank you for your help, but I figured it out!

          Here is my result for those who were curious:

          <table><tr>
          
          <?php 
          
          $array = explode (' ', $_POST['images']);
          
          $counted = count($array);
          
          echo $counted;
          
          $tdnum = 0;
          $counter = 0;
          
          for ($c = 0; $c <= $counted-1; $c += 1)
          {
          	echo "<td>".$array[$c]."</td>";
          
          $counter += 1;
          
          if ($counter == 3)
          {
          echo "</tr><tr>";
          for ($run = 1; $run <= 3; $run += 1)
          	{
          		$tdnum += 1;
          		echo "<td>".$tdnum."</td>";
          	}
          $counter = 0;
          echo "</tr><tr>";
          }
          }
          ?>
          
          </tr></table>

            $array = explode (' ', $_POST['images']);

            $counted = count($array);

            echo '<table>';

            $tdimg = '';
            $tdc = '';

            for ($c = 1; $c <= $counted; $c ++)
            {
            $tdimg.='<td>'.$array[$c-1].'</td>';
            $tdc.='<td>'.$c.'</td>';
            if($c%3==0){
            echo '<tr>',$tdimg,'</tr><tr>',$tdc,'</tr>';
            $tdimg='';
            $tdc='';
            }

            }
            echo '</table>';
            </tr></table>

              Write a Reply...