1

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_order_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

Alvin Jorge
  • 87
  • 2
  • 10
  • 11
    Instead of posting a ton of code with very little explanation, please describe your goal in words and the specific problems you have turning it into code. – deceze Sep 06 '11 at 23:46
  • @deceze Sir I am sorry for posting that question.. I know it's easy for most but I am a newbie programmer.. 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. – Alvin Jorge Sep 06 '11 at 23:54
  • 1
    in addition, pasting directly from code and leaving in information about your client could introduce attempts to hack your system. – omasdg Sep 06 '11 at 23:56

1 Answers1

1

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?

omasdg
  • 116
  • 3
  • Because this form should generate a report... so I have two dates, datefrom and dateto... also, I'm not sure of my codes too that's why I posted it on forum so experts like you could check about it and give me insights... Sir @omasdg here is the format of my date is 13/09/2011 10:05 – Alvin Jorge Sep 07 '11 at 02:05
  • Sir In my view_apr.php, I was actually trying to parse a month.. since in the option above there is choices to choose as to what report i want to generate.. whether monthly, weekly or daily.. but I do'nt know how to parse.. so maybe you could help me on this. Thanks you very much. – Alvin Jorge Sep 07 '11 at 02:12
  • How do you store the date in your database? timestamp(date+time) or simply a date? – omasdg Sep 07 '11 at 02:24
  • Right now, you have 2 select elements with the same name "ssa_group". You want to rename one of them to differentiate between them in your view_apr.php, or else you will be posting $_POST['ssa_group'] x 2, $_POST['duration'], $_POST['calendar1'], $_POST['calendar2'] – omasdg Sep 07 '11 at 02:33
  • there is actually a column for date in some of our tables in our databases. it is timestamp (date=time) like the format on the above comment.. – Alvin Jorge Sep 07 '11 at 02:53
  • it took me quite a while, but i think i understand your sql now.. only thing is i don't have time to respond today. – omasdg Sep 07 '11 at 03:12