I've been dinking with this since yesterday, dinked with it in the past and still not solid solution.
Scenario: I have a list that grows and gets smaller on the fly. There may be 8 things in the list, or 108 things in the list.
For page design purposes I decided I want this list in a table with the number of cells in the table increasing and decreaseing with the size of the list to a maximum number of cells. As the list grows, the number of items in each cell will increase so that an equal number of items is in the first 6 cells, with overflow(if there is an overflow) of items going in the last cell.
I couldnt get the round(); function to work properly for me because I always want the number to round to the next highest whole number regardless of the size of the decimal. Example: 5.00000000001 would round up to 6.
Now I am forced to make this work because my work around that has been working for months, suddenly choked and the script dies.
Quote:
<?
$count_categories_build=count($categories_build);
$how_many_category_columns=$count_categories_build/7;
$this_many_category_columns=explode(".", $how_many_category_columns);
if ($this_many_category_columns[1])
{
// True, there is a decimal
// round up.
$columns=$this_many_category_columns[0]+1;
}
else
{
$columns =$this_many_category_columns[0];
}
?>
|
This snippet of code has worked for a very long time, but over the weekend PHP suddenly see's $columns as an array and errors:
Quote:
$count_table=1;
foreach ($categories_build as $key=>$value)
{
$row=$count_table/$columns;
$ex_row=explode(".", $row);
$categories .=$value;
if (!$ex_row[1])
{
$categories.="</td><td>";
}
$count_table++;
}
|
I created a work around for the work around, but now if there is exactly the same number if entries in each of the columns, the last column is created with nothing in it.
Any suggestions on how to make round(); work for me?
-