Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 2005-05-12, 03:01 PM   #1
Barron
You tried your best and you failed miserably. The lesson is 'never try'
 
Join Date: Oct 2004
Posts: 166
PHP function round();

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?


-
Barron is offline   Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:17 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc