Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $sites = site_list();
  4. $site_first = array();
  5. foreach($sites as $row) {
  6.     if(!array_key_exists($row['city'], $site_first)) {
  7.         $site_first[$row['city']] = array();
  8.     }
  9.     array_push( $site_first[$row['city']],$row );
  10. }
  11. //$i = 1;
  12. echo '<!-- '. print_r($site_first,TRUE) . '-->'.PHP_EOL;
  13.  
  14. $db=$site_first;
  15.  
  16. $columns=3;
  17. $count=count($db);
  18. $percol=intval(ceil($count/$columns));
  19.  
  20. $curcol=0;
  21. $curctr=0;
  22. foreach($db as $city)
  23. {
  24.    foreach($city as $site)
  25.    {
  26.       $td[$curcol][]=$site[1].'<br />'.$site[3].'<br />'.$site[8];
  27.       $curctr++;
  28.       if($curctr==$percol)
  29.       {
  30.         $curctr=0;
  31.         $curcol++;
  32.       }
  33.    }
  34. }
  35. echo "<table>".PHP_EOL;
  36. for($i=0;$i<$percol;$i++)
  37. {
  38.   echo " <tr>".PHP_EOL;
  39.   for($j=0;$j<$columns;$j++)
  40.     echo '    <td>'. (isset($td[$j][$i])?$td[$j][$i]:'&nbsp;') .'</td>'.PHP_EOL;
  41.   echo " </tr>".PHP_EOL;
  42. }
  43. echo "</table>".PHP_EOL;
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement