ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

PHP gurus required...!



  20VT Clio & 9-5 HOT
Im currently building a website which has an online booking form....

I more of a designer than a programmer lol, but i have found an ideal bit of code which allows booking dates to be requested, and logged in a SQL DB etc. All works good!

The prob is occasionally iv noticed that say monday to monday is selected in the calendar, when it gets to the next step, it sometimes shows the number of days as 6.9583333333333 instead of 7 days!

Does anyone know a bit of php code maybe that will round this particular number off to the nearest whole number. i.e 7?

Iv done a bit of googling but not found a great deal as i dont know much about php at the mo!
 

sn00p

ClioSport Club Member
  A blue one.
printf will also do what you want if you're wanting to output, it has the added advantage that you can zero pad the output too.
 
Can you give the code you are using to get the valuse of Monday to Monday? There might be another way to do that which only gives whole numbers of days.
 

KDF

  Audi TT Stronic
Oh and its strange you should be doing this as I have already written a complete online booking system in php for my work, and just recently ive been recoding it to use ajax.. its just about done so any help/tips just drop me a PM.
 

sn00p

ClioSport Club Member
  A blue one.
Oh and its strange you should be doing this as I have already written a complete online booking system in php for my work, and just recently ive been recoding it to use ajax.. its just about done so any help/tips just drop me a PM.

I've just finished up our new cms/store/basket which I wrote from scratch in php. Currently it doesn't use AJAX for adding items to the basket, but it'd be a 10 minute job to re-organise and add I think.

Did you do all the AJAX stuff yourself or use something like PEAR::AJAX? I've used PEAR::AJAX on the backend of the website in a few places and it worked very well and uber simply.

Bottom line, pear fricking rules!
 

KDF

  Audi TT Stronic
Oh and its strange you should be doing this as I have already written a complete online booking system in php for my work, and just recently ive been recoding it to use ajax.. its just about done so any help/tips just drop me a PM.

I've just finished up our new cms/store/basket which I wrote from scratch in php. Currently it doesn't use AJAX for adding items to the basket, but it'd be a 10 minute job to re-organise and add I think.

Did you do all the AJAX stuff yourself or use something like PEAR::AJAX? I've used PEAR::AJAX on the backend of the website in a few places and it worked very well and uber simply.

Bottom line, pear fricking rules!

Wrote all the code myself, although PEAR is great for saving time !
 

KDF

  Audi TT Stronic
I may be wrong but I dont think round() is what your looking for..

it will round something like 3.4 down to 3... if your looking to round up to a whole number then you should use ceil() which would return a value of 3.4 as 4
 
  20VT Clio & 9-5 HOT
hmmm i dunno mate, it does appear to have done the trick tho

it was displaying 6.899999999 instead of 7 days for some reason, but now it always shows 7 which is what i wanted! :) i just needed it to round to the nearest whole number.

i cant get the ceil() php page to open at the mo to take a look.
 

sn00p

ClioSport Club Member
  A blue one.
hmmm i dunno mate, it does appear to have done the trick tho

it was displaying 6.899999999 instead of 7 days for some reason, but now it always shows 7 which is what i wanted! :) i just needed it to round to the nearest whole number.

i cant get the ceil() php page to open at the mo to take a look.

I'm with KDF. Sounds like you want the ceiling and not a rounded number. It works in your case because it'll round up. I assume (and KDF seems too as well) that if you got a result of 6.1 you'd want the answer to be 7, as in "days of the week" that's what it'd be. Round will give you 6, ceil will give you 7.

some examples.

Code:
        6.1   6.5   6.7
round    6     7     7
floor    6     6     6
ceil     7     7     7
 

KDF

  Audi TT Stronic
yes snoop that was exactly what i was getting at..... just not as elequently put ;)
 
  20VT Clio & 9-5 HOT
ok i may change it, cheers for the info lads!

tbh i dunno why the fook it was sometimes coming up with the 6.8999999999999 instead of 7. not just that, but same for other days too. 16.89999999999 etc. always the same decimal tho!

here is the bit of code (with the round added)

PHP:
$dayscount = round($span->Span('d', $fromdate->TimeStamp(), $todate->TimeStamp()), 0);
 

KDF

  Audi TT Stronic
ok i may change it, cheers for the info lads!

tbh i dunno why the fook it was sometimes coming up with the 6.8999999999999 instead of 7. not just that, but same for other days too. 16.89999999999 etc. always the same decimal tho!

here is the bit of code (with the round added)

PHP:
$dayscount = round($span->Span('d', $fromdate->TimeStamp(), $todate->TimeStamp()), 0);

Ah, class's .. good lad ;) you ought to see some of the code ive had to fix .. shocking ! lol

if you look at www.php.net/round you will see it will not fully round up a decimal.. eg

echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06

as you can see the value it would output is listed after the //

Like I said, I didnt think that was what you were looking for, and if you script is relying on whole numbers then it will cause you major issues.. use ceil() ;)
 


Top