html - Echoing PHP API Data In 3 Columns -


i getting website design ideas website api.

currently setup displays these designs in table 1 column, have on 40 items need displayed in table, id prefer display in 3 columns. have tried using i=0 ++ things etc couldnt work out put it.

here code far:

<?php         $output = json_decode($output);     curl_close($ch);         echo '<table border="1">';        foreach($output $template) {         echo '<tr>';         echo '<td>' . $template->template_name . '</td>';         echo '</tr>' . '<tr>';         echo '<td><a href="'. $template->preview_url .'" target="_blank"><img src="' . $template->thumbnail_url. '"></a>' . '</td>';         echo '<tr>';         echo '<td><form method="get" action=' . $_server['php_self'] . '>';         echo '<input type="hidden" name="template_id" value="' . $template->template_id . '">';         echo '<input type="url" name="original_url" placeholder="existing site url">'.'<br />';         echo '<input type="email" name="email" placeholder="your e-mail" required>'.'<br />';         echo '<button type="submit">choose site</button>';         echo '</form></td>';           echo '</tr>';      }       echo '</table>'; }   ?> 

the output includes of website templates. putting rows.the first row contains name of template, second picture of website template , third form working on.

my question how can nest loop 3 columns, each row 3 different designs?

many in advance

the common idea may following, example:

<?php   $array = [0, 1, 2, 3, 4, 5, 6, 7, 8]; $i = 1;  echo "<table>"; foreach ($array $arr) {     if ($i % 3 === 0) {        echo "<tr class='class_3'>";     } else if ($i % 2 === 0) {        echo "<tr class='class_2'>";     } else {        echo "<tr class='class_1'>";     }      echo '<td>'.($i++).'</td>';     echo '<td>'.($i++).'</td>';     echo '<td>'.($i++).'</td>';      echo "</tr>";     //$i++; 123 456 } echo '</table>';              ?> 

update: more specific example:

<?php  $assoc_array = json_decode(' [    {"template_id": "1","template_name":"a", "preview_url":"url_1"},    {"template_id": "2","template_name":"b", "preview_url":"url_2"},    {"template_id": "3","template_name":"c", "preview_url":"url_3"},    {"template_id": "4","template_name":"d", "preview_url":"url_4"},    {"template_id": "5","template_name":"e", "preview_url":"url_5"},    {"template_id": "6","template_name":"f", "preview_url":"url_6"},    {"template_id": "7","template_name":"g", "preview_url":"url_7"},    {"template_id": "8","template_name":"h", "preview_url":"url_8"},    {"template_id": "9","template_name":"i", "preview_url":"url_9"},    {"template_id": "10","template_name":"j", "preview_url":"url_10"} ] ', true);  echo '<table>'; for($i = 0; $i < sizeof($assoc_array); $i++) {     if ($i % 3 === 0) {        echo "<tr class='class_3'>";     } else if ($i % 2 === 0) {        echo "<tr class='class_2'>";     } else {        echo "<tr class='class_1'>";     }         echo '<td>'.$assoc_array[$i]['template_name'].'</td>';      if(isset($assoc_array[++$i]['template_name'])) {        echo '<td>'.$assoc_array[$i]['template_name'].'</td>';     }      if(isset($assoc_array[++$i]['template_name'])) {        echo '<td>'.$assoc_array[$i]['template_name'].'</td>';     }             echo '</tr>';         } echo '</table>';     ?> 

you'll get:

a       b       c    d       e       f    g       h          j 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -