Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6536951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:33:31+00:00 2026-05-25T10:33:31+00:00

I am trying to make a project wherein it display the 3 previous monnth

  • 0

I am trying to make a project wherein it display the 3 previous monnth and the current month.. now my problem is I dont know where or how to reflect this mysql data into a table in php… can anyone taught me please?

Pardon me if I’m not good in explaining to you the system because I’m just a trying hard programmer..

this should be how the table will look like:
http://www.fileden.com/files/2011/7/27/3174077//1.JPG

here is the php codes and mysql query that i want to put into a table:

<form action="" method="post" class="niceform">
<fieldset>
    <legend>Job Orders</legend>\
    <table>
<tr>
<th>SSA</th>
<th>Months</th>
</tr>

         <?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";
}

//march
else if ($conditionmonth == '3')
{

$sql="SELECT
a.specialist_partner_ID
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-03-01', INTERVAL 3 MONTH) and       DATE_SUB('2011-03-31', INTERVAL 3 MONTH) THEN a.job_order_number ELSE null END) As December
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-03-01', INTERVAL 2 MONTH) and  DATE_SUB('2011-03-31', INTERVAL 2 MONTH) THEN a.job_order_number ELSE null END) As Jauary
,count(CASE WHEN a.receivedDate between DATE_SUB('2011-03-01', INTERVAL 1 MONTH) and  DATE_SUB('2011-03-31', INTERVAL 1 MONTH) THEN a.job_order_number ELSE null END) As February
,count(CASE WHEN a.receivedDate between '2011-03-01' and  '2011-03-31'THEN a.job_order_number ELSE null END) As March
,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

while ($row = mysql_fetch_row($sql)
{

} 
?>
  </tr></table>
</fieldset>

the condition is when I select a month to view the report for that month, ex January, only data from January will only be visible and the last 3 consrctive month, ex december and november

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:33:32+00:00Added an answer on May 25, 2026 at 10:33 am

    Given that a table is build up using this kind of data:

    <tr>
      <td>item1</td>
      <td>item2</td>
    </tr>
    

    It’s really simple to build the table using SQL, just bracket the data using the table tags:

    SQL only code, not recommended because it leaves open a XSS security hole!
    Only use this if you are 100% sure the data inside your DB is safe

    /*escape all data coming from a user */
    /*or even better just escape all incoming data *period* */
    $SSAID = mysql_real_escape_string($_SESSION['SESS_SSA_ID']);
    
    /*don't use 2 queries if you can do it in one */  
    $result = mysql_query("SELECT CONCAT('<tr>',GROUP_CONCAT(
                                  CONCAT('<td>',ug.group_name,</td>), SEPARATOR ' ')
                                  ,'</tr>') as tablestring 
                          FROM user_group ug
                          INNER JOIN user u ON (ug.usr_group_ID = u.user_group_id)
                          WHERE u.SSA_ID = ''$SSAID' )";
    
    $row = mysql_fetch_row($result);
    echo "here comes the table";
    echo $row['tablestring'];
    

    This code constructs the whole table in SQL. An other option is to loop though the values and piece together the table in a while loop:

    Code example using a while loop, escapes the output, preventing XSS

    $result = mysql_query("SELECT ug.group_name 
                          FROM user_group ug
                          INNER JOIN user u ON (ug.usr_group_ID = u.user_group_id)
                          WHERE u.SSA_ID = ''$SSAID' )";
    $table = "<tr>";
    while ($row = mysql_fetch_row($result));
    {
      $table .= "<td>".htmlspecialchars($row['group_name'], ENT_QUOTES, 'UTF-8')."</td>";
    }
    $table .= "</tr>";
    echo "here comes the table";
    echo $table;
    

    Points to remember

    • Use mysql_real_escape_string() on all $vars you inject into a SQL-statement.
    • Always escape data you echo onto the screen using htmlspecialchars() to prevent XSS.
    • Get out of the select * habit, only select what you need.
    • Don’t use two queries and use php as a courier between them, use one query instead, see a tutorial on SQL joins.

    Links
    SQL-injection: How does the SQL injection from the "Bobby Tables" XKCD comic work?
    XSS prevention: How to prevent XSS with HTML/PHP?
    php-MySQL tutorial: http://www.tizag.com/mysqlTutorial/
    group_concat: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a WebForms project and ASP.NET MVC per this question
I still trying to make my project with GWT and Maven works. Now, i
I'm trying to understand how this works. My idea is to make administrable project
I'm trying to make a pom.xml for my project. This project will use GWT
I am trying to make spring+hibernate+ant project And at the moment I get this
I'm trying to make my project compile under GCC (Visual Studio compiles it flawlessly).
I am trying to make a tictactoe project in jQuery and I am having
I'm trying to make an update of one project of mine, but i don't
I am trying to make ajax requests in my project, but I do not
Im trying to make a photoshop like application for my college project in c#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.