开发者

parsing date in php

I need to be able to compare some month names I have in an array.

It would be nice if there were some direct way or sample of it..

I have this code but i dont know how to parse the given condition (the month).. I don't know what code to use to parse the month and on how to call it to the other page the view_apr.php. I don't know where or how exactly to start because I'm just a beginner programmer.. please help me.

Goal: I want that when I have chosen a month (example: I have chosen january), it will direct me into that month and display all the datas within that month only...I am trying to make a project wherein it display the 3 previous month and the current month.

apr.php code:

<div class="main_content">
<?php
    include '../../includes/topnavModule.php';
    $SSAID = $_SESSION['SESS_SSA_ID'];  
    $query = mysql_query("SELECT * FROM user WHERE SSA_ID = '$SSAID'");
    $result = mysql_fetch_array($query);
    $userGroupID = $result['user_group_ID'];

    $query1 = mysql_query("SELECT * FROM user_group WHERE usr_group_ID =  '$userGroupID'");
    $result1 = mysql_fetch_array($query1);
    $groupName = $result1['group_name'];

    if ($groupName == "SSA Group")
    {
?>

<div class="center_content">  


<div class="right_content1">   
<div class="form" align="left">

     <form name = "form1" id="form1" action="view_apr.php" method="post" class="niceform">

<fieldset>
  <legend>Production Summary</legend>

   <dl>
        <dt><label for="type">Type:</label></dt>
 <dd>
            <select size="1" name="ssa_group" id="ssa_group" tabindex="3" class="combo" onchange="getSSA('ssaid.php?ssa='+this.value)">

                <option value="all">All</option>
                <option value="1">Sourcing</option>
                <option value="0">Mining</option>

            </select>
        </dd>
    </dl>

       <dl>
        <dt><label for="languages">Reports for:</label></dt>
<dd>
            <select size="1" name="duration" id="duration">
                <option value="0">Monthly</option>
                <option value="1">Weekly</option>
                <option value="2">Daily</option>
                <?php 



                ?>

            </select>
        </dd>
    </dl>

     <dl>
        <dt><label for="sourcing">SSA:</label></dt>
<dd>

<div id="SSA">
        <select size="1" name="ssa_group" id="0" tabindex="1" class="combo" >
                <?php
                    $result = mysql_query("SELECT * FROM staffing_specialist_asst") or   die(mysql_error());

                    while($row = mysql_fetch_assoc($result)) 
                    {
                    echo "<option value='{$row['last_name']}'>{$row['last_name']}   </option>";
                    }
                ?>
        </select>
</div>             


        </dd>
    </dl>
<dl>

<?php

$SSAID = $_SESSION['SESS_SSA_ID'];

$query = mysql_query("SELECT * FROM user WHERE SSA_ID = '$SSAID'");
$result = mysql_fetch_array($query);
$userGroupID = $result['user_group_ID'];

$query1 = mysql_query("SELECT * FROM user_group WHERE usr_group_ID = '$userGroupID'");
$result1 = mysql_fetch_array($query1);
$groupName = $result1['group_name'];

if ($groupName == "SSA Group")
{
echo "
                    <dl>
                    <dt style=\"float:left;\"><label for=\"\" id = 'label'>Date From:  </label></dt>
                    <dd><input type=\"text\" name=\"timestamp\" id=\"calendar1\"   class=\"calendarFocus\" size=\"54\"/>
                    </dd>
                </dl>
                <dl>
                    <dt style=\"float:left;\"><label for=\"\" id =\"label\">Date To:     </label></dt>
                    <dd><input type=\"text\" name=\"timestamp1\" id=\"calendar1\"   class=\"calendarFocus\" size=\"54\"/> 
                     </dd>
                </dl>
                                    <dl class=\"submit\">
                <input type=\"submit\" name=\"search\" class=\"NFButton\"   value=\"Search\" width=\"126\" height=\"18\" /> 
                </dl>  

</fieldset>
</form>
</div>";
 }
 ?>
 </dl>
</fieldset>
</form>
</div>
</div>
</div>  



<div class="clear"></div>
</div>


<div class="footer">

    <div class="left_footer">Extramind | Contact: (02) 866-1234 <a href="http://xmindoutsourcing.com">XMind</a></div>
    <div class="right_footer"><a href="http://xmindoutsourcing.com"><img src="../../images/xmind.gif" alt="" height="52" border="0" title="" /></a></div>
</div>

</div>  

<?php
    }//end if

    else{
        echo "<SCRIPT LANGUAGE='javascript'> redirect() ;</SCRIPT>";
    }
?>

</body>
</html>


<?php
$SSAID = $_SESSION['SESS_SSA_ID'];

if (isset($_POST['submit']))
{


//get the SS 
$name =  $_POST['ss'];
$SS= explode("-", $name);
$lastName = $SS[0];
$firstName = $SS[1];


//get the SS ID
$result1 = mysql_query("SELECT * from staffing_specialist WHERE last_name LIKE '$lastName' AND first_name LIKE '$firstName'");
$row = mysql_fetch_array($result1);
$SSID = $row['SS_ID'];



if($result1){
    echo "<SCRIPT LANGUAGE='javascript'> confirmation() ;</SCRIPT>";
}
else{
    echo "<SCRIPT LANGUAGE='javascript'> confirmationError() ;</SCRIPT>";
  }
}

?>

<?php ob_flush(); ?>

view_apr.php code:

<?php

$datefrom= $_POST['timestamp'];
$dateto=$_POST['timestamp1'];

$parsemonth="";
$parseday ="01";

$conditionmonth=$parsemonth-3;


//january
if ($conditionmonth == '1'){

$sql="SELECT
a.specialist_partner_ID
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-01-01', INTERVAL 3 MONTH) and  DATE_SUB('2011-09-30', INTERVAL 3 MONTH) THEN a.job_order_number ELSE null END) As December
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-01-01', INTERVAL 2 MONTH) and  DATE_SUB('2011-09-30', INTERVAL 2 MONTH) THEN a.job_order_number ELSE null END) As November
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-01-01', INTERVAL 1 MONTH) and  DATE_SUB('2011-09-30', INTERVAL 1 MONTH) THEN a.job_order_number ELSE null END) As October 
,count(CASE WHEN a.receivedDate between '2011-01-01' and  '2011-01-30'THEN  a.job_order_number ELSE null END) As Jauary
,count(job_order_number) As Total
FROM jo_partner a
WHERE a.receivedDate BETWEEN '2011-01-01' AND '2011-12-31'
GROUP BY a.specialist_partner_ID";
}

//february
else if ($conditionmonth == '2'){

$sql="SELECT a.specialist_partner_ID
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-02-01', INTERVAL 11 MONTH) and  DATE_SUB('2011-02-29', INTERVAL 3 MONTH) THEN a.job_order_number ELSE null END) As November
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-02-01', INTERVAL 10 MONTH) and  DATE_SUB('2011-02-29', INTERVAL 2 MONTH) THEN a.job_orde开发者_如何学编程r_number ELSE null END) As December
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-02-01', INTERVAL 9 MONTH) and  DATE_SUB('2011-02-29', INTERVAL 1 MONTH) THEN a.job_order_number ELSE null END) As January
,count(CASE WHEN a.receivedDate between '2011-02-01' and  '2011-02-29'THEN a.job_order_number ELSE null END) As February
,count(job_order_number) As Total
FROM jo_partner a
WHERE a.receivedDate BETWEEN '2011-01-01' AND '2011-12-31'
GROUP BY a.specialist_partner_ID";
}

and so on and so forth up to december


i cleaned your apr.php for readability, but for some reason you have two if(groupname=="SSA Group") statements, one which starts at the very beginning and ends at the footer, and another one which starts inside that same condition?? And two selects with the same name. One with values:all, 1, 0, and another one with lastname values generated with a loop.

<form name="form1" id="form1" action="view_apr.php" method="post">
<fieldset>

<legend>Production Summary</legend>

<label for="type">Type:</label>

<select name="ssa_group" id="ssa_group">
<option value="all">All</option>
<option value="1">Sourcing</option>
<option value="0">Mining</option>
</select>

<label for="languages">Reports for:</label>

<select name="duration" id="duration">
<option value="0">Monthly</option>
<option value="1">Weekly</option>
<option value="2">Daily</option>
</select>

<label for="sourcing">SSA:</label>

<select name="ssa_group" id="0">
//foreach
<option value='{$row['last_name']}'>{$row['last_name']}</option>
</select>

<label id='label'>Date From:  </label>
<input type="text" name="timestamp" id="calendar1" />

<label id ="label">Date To:     </label>
<input type="text" name="timestamp1" id="calendar1" /> 

<input type="submit" name="search" value="Search" /> 
</fieldset>
</form>

his view_apr begins with

$datefrom= $_POST['timestamp'];
$dateto=$_POST['timestamp1'];

$parsemonth="";
$parseday ="01";

$conditionmonth=$parsemonth-3;

//january
if ($conditionmonth == '1'){

im having trouble with this one... As if you weren't using the posted data at all. Plus you have a typo in the SQL for januarys condition, where you count something as "Jauary"

You have 2 variables, datefrom and dateto. What's the format of the dates your posting them with?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜