Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Calculation help please

Codes here !

Moderators: macek, egami, gesf

Calculation help please

Postby CharlyAnderson » Wed Apr 16, 2014 1:52 am

Good morning,

I am very new to PHP and wondered if someone could help me add something onto a PHP calculation?

If someone could help it would be a HUGE help :-)

Basically I am working on a due date calculator... Currently it tells you when you due date will be from last period date. I need it to also say how many weeks pregnant the person currently is.

So last period date -> current date (displayed in weeks).

This is the PHP

Code: Select all
function ovpredct2_datechooser($name,$value="")
    if(empty($value)) $value=date("Y-m-d");
    $chooser.="<select name=".$name."month>";
        if($i==$month) $selected='selected';
        else $selected='';
        $chooser.="<option $selected value=$i>$months[$i]</option>";
    $chooser.="</select> / ";
    $chooser.="<select name=".$name."day>";
        if($i==$day) $selected='selected';
        else $selected='';
        $chooser.="<option $selected>$i</option>";
    $chooser.="</select> / ";
    $chooser.="<select name=".$name."year>";
        if($i==$year) $selected='selected';
        else $selected='';
        $chooser.="<option $selected>$i</option>";
    $chooser.="</select> ";     
    return $chooser;

function ovpredct2_generate_html()
    //construct the calculator page     
    $ovcalc="<style type=\"text/css\">
        //last cycle date
        //convert to time
        //first fertile day
        $firstdaytime=$lasttime + $_POST[days]*24*3600 - 16*24*3600;
        $firstday=date("F d, Y",$firstdaytime);
        //last fertile day
        $lastdaytime=$lasttime + $_POST[days]*24*3600 - 12*24*3600;
        $lastday=date("F d, Y",$lastdaytime);
        //have to adjust due date?
        $diff=$_POST[days] - 28;
        //due date $date + 280 days
        $duedatetime=$lasttime + 280*24*3600 + $diff*24*3600;
        $duedate=date("F d, Y",$duedatetime);
        //the result is here
        $ovcalc.='<div class="ovpredct2_table">
        Your estimated due date is <strong>'.$duedate.'</strong>     
        <p align="center"><input type="button" value="Calculate again!" onclick="javascript:history.back();"></p>
        $ovcalc.='<div class="ovpredct2_table">
        <form method="post">
        When was the first day of your last period?<br /><br />
        Usual number of days in your cycle: <select name="days">';
            if($i==28) $selected='selected';
            else $selected='';
            $ovcalc.="<option $selected value='$i'>$i</option>";
        <p align="center"><input type="submit" name="calculator_ok" value="Calculate"></p>

    return $ovcalc;

New php-forum User
New php-forum User
Posts: 1
Joined: Wed Apr 16, 2014 1:49 am

Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.