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

  • Home
  • SEARCH
  • 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 6542183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:11:41+00:00 2026-05-25T11:11:41+00:00

I have this several lines of code. It’s function is that it will create

  • 0

I have this several lines of code. It’s function is that it will create a table based on the date that is inputted. Example if the date today is Monday, then it will result into 5 columns (mon, tue, wed, thu, fri) or if today is Tuesday, it will result to 4 columns (tue, wed, thu, fri) and so on and so forth. My problem is that the code i’m using is too long. I want to ask if it could be possible to shorten this? If it is possible, could you taught me how?

Here is my code:

if ($jd2 == 'Monday')
{
    $sql="SELECT
        a.specialist_partner_ID
        ,count(CASE WHEN a.receivedDate between '".$datefrom."' and '".$dateto."' THEN a.job_order_number ELSE null END) As THU
        ,count(CASE WHEN a.receivedDate between DATE_SUB('".$datefrom."', INTERVAL 1 DAY) and  DATE_SUB('".$dateto."', INTERVAL 1 DAY) THEN a.job_order_number ELSE null END) As FRI
        ,count(job_order_number) As Total
        FROM jo_partner a
        WHERE a.receivedDate BETWEEN '".$datefrom."' AND '".$dateto."'
        GROUP BY a.specialist_partner_ID";
}

//echo $sql;

echo "<table width='200'  border='2'>";
echo "<tr>";
echo "<td>MON</td>";
echo "<td>THU</td>";
echo "<td>WED</td>";
echo "<td>THU</td>";
echo "<td>FRI</td>";
echo "<td>total</td>";
echo "</tr>";
}


$query = mysql_query($sql);
while($row = mysql_fetch_array($query))
{
    $MON = $row['MON'];
    $TUE = $row['TUE'];
    $WED = $row['WED'];
    $THU = $row['THU'];
    $FRI = $row['FRI'];
    $Total = $row['Total'];

    if ($jd2 == 'Monday')
    {
        echo "<tr>";
        echo "<td>$MON</td>";
        echo "<td>$TUE</td>";
        echo "<td>$WED</td>";
        echo "<td>$THU</td>";
        echo "<td>$FRI</td>";
        echo "<td>$Total</td>";
        echo "</tr>";
    }
}
echo "</table>";

if ($jd2 == 'Tuesday')
{
    $sql="SELECT
        a.specialist_partner_ID
        ,count(CASE WHEN a.receivedDate between '".$datefrom."' and '".$dateto."' THEN a.job_order_number ELSE null END) As THU
        ,count(CASE WHEN a.receivedDate between DATE_SUB('".$datefrom."', INTERVAL 1 DAY) and  DATE_SUB('".$dateto."', INTERVAL 1 DAY) THEN a.job_order_number ELSE null END) As FRI
        ,count(job_order_number) As Total
        FROM jo_partner a
        WHERE a.receivedDate BETWEEN '".$datefrom."' AND '".$dateto."'
        GROUP BY a.specialist_partner_ID";

    //echo $sql;

    echo "<table width='200'  border='2'>";
    echo "<tr>";
    echo "<td>TUE</td>";
    echo "<td>WED</td>";
    echo "<td>THU</td>";
    echo "<td>FRI</td>";
    echo "<td>total</td>";
    echo "</tr>";
}

$query = mysql_query($sql);
while($row = mysql_fetch_array($query))
{
    $TUE = $row['TUE'];
    $WED = $row['WED'];
    $THU = $row['THU'];
    $FRI = $row['FRI'];
    $Total = $row['Total'];

    if ($jd2 == 'Tueday')
    {
        echo "<tr>";
        echo "<td>$TUE</td>";
        echo "<td>$WED</td>";
        echo "<td>$THU</td>";
        echo "<td>$FRI</td>";
        echo "<td>$Total</td>";
        echo "</tr>";
    }
}
echo "</table>";


if ($jd2 == 'Wednesday')
{
    $sql="SELECT
        a.specialist_partner_ID
        ,count(CASE WHEN a.receivedDate between '".$datefrom."' and '".$dateto."' THEN a.job_order_number ELSE null END) As THU
        ,count(CASE WHEN a.receivedDate between DATE_SUB('".$datefrom."', INTERVAL 1 DAY) and  DATE_SUB('".$dateto."', INTERVAL 1 DAY) THEN a.job_order_number ELSE null END) As FRI
        ,count(job_order_number) As Total
        FROM jo_partner a
        WHERE a.receivedDate BETWEEN '".$datefrom."' AND '".$dateto."'
        GROUP BY a.specialist_partner_ID";

    //echo $sql;

    echo "<table width='200'  border='2'>";
    echo "<tr>";
    echo "<td>WED</td>";
    echo "<td>THU</td>";
    echo "<td>FRI</td>";
    echo "<td>total</td>";
    echo "</tr>";
}


$query = mysql_query($sql);
while($row = mysql_fetch_array($query))
{
    $WED = $row['WED'];
    $THU = $row['THU'];
    $FRI = $row['FRI'];
    $Total = $row['Total'];

    if ($jd2 == 'Wednesday')
    {
        echo "<tr>";
        echo "<td>$WED</td>";
        echo "<td>$THU</td>";
        echo "<td>$FRI</td>";
        echo "<td>$Total</td>";
        echo "</tr>";
    }
}
echo "</table>";
  • 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-25T11:11:42+00:00Added an answer on May 25, 2026 at 11:11 am

    Maybe this can give you an idea:

    <?php
    
    //to make testing easier
    $jd2 = isset($_GET['jd2'])?$_GET['jd2']:'Monday';
    
    //array with abbr
    $days = array(
        'Monday' => 'MON',
        'Tuesday' => 'TUE',
        'Wednesday' => 'WED',
        'Thursday' => 'THU',
        'Friday' => 'FRI');
    
    //this will hold the tr content
    $tr_content = '';
    foreach(array_reverse($days,true) as $day => $abbr){
        $tr_content = "<td>$day</td>".$tr_content;
        if($jd2 == $day) break;
    }
    echo "<table border=1><tr>$tr_content</tr></table>";
    
    //create a few links to try
    foreach($days as $day => $i){
        echo "<a href='?jd2=$day'>$day</a><br>";
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several hundred lines of code like this: if (c.SomeValue == null ||
I have several forms like this: <table width=100% border=0 cellpadding=0 cellspacing=0 class=table_std> <tr id=exam_String_newValue_row>
I have several directories that look like this: dir1/ |_foo.txt |_bar.txt dir2/ |_qux.txt |_bar.txt
We have several areas where code like this can be seen public Map extractData(ResultSet
I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A
I have several unordered lists that I want to display like this: <ul> <li><img></li>
Let's say I have several lines of code to clarify specific settings on a
Possible Duplicate: iif equivalent in c# I have several lines of code using IIf
/** Constant <code>IDX_USER=IDX_+ USER_ID</code> */ I have several lines of code which was generated
Several lines of code are worth a thousand words: I have three simple files:

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.