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 8636817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:18:56+00:00 2026-06-12T10:18:56+00:00

I have a page with some PHP that looks like this: <table> <thead> <tr>

  • 0

I have a page with some PHP that looks like this:

<table>
    <thead>
        <tr>
            <th class="wheniwant">Date</th>
            <th class="wheniwant">Income Amount</th>
            <th class="wheniwant">Expense Amount</th>
        </tr>
    </thead>

    <?php
    //DB CONNECTION

    $varDatePaid = ""; $varIncomePaid =""; $varExpensePaid = "";

    $sql = mysql_query( 
        "
            SELECT DATE_FORMAT(`date_paid`, '%Y-%m') `date_paid`,
            SUM(CASE WHEN `categoryType` = 'Income' THEN `amount_paid` END) `IncomeAmount`,
            SUM(CASE WHEN `categoryType` = 'Expense' THEN `amount_paid` END) `ExpenseAmount`
            FROM `accounting`
            GROUP BY DATE_FORMAT(`date_paid`, '%Y-%m')
        "
     );


    while($row = mysql_fetch_array($sql))
        {
            $varDatePaid = $row['date_paid'];
            $varIncomePaid = $row['IncomeAmount'];
            $varExpensePaid = $row['ExpenseAmount'];                        
    ?>


    <tr>
        <td><?php echo $varDatePaid; ?></td>
        <td><?php echo $varIncomePaid; ?></td>
        <td><?php echo $varExpensePaid; ?></td>
        </tr>

    <?php   

        }
    ?>
</table>

This returns a table like:

Screenshot

I want to then add something:

$sql_query = "SELECT id, DATE_FORMAT(`date_paid`, '%Y') AS year FROM accounting GROUP BY year ORDER BY year DESC";


$result = mysql_query($sql_query) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
echo '<option value='. $row['year'] . '>'. $row['year'] . '</option>';

To create some sort of filter to limit the result to a particular year. How do I do this without leaving the page?

  • 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-06-12T10:18:57+00:00Added an answer on June 12, 2026 at 10:18 am

    You first define the dropdown in the html and submit it when the selected value changes:

    <form id="myForm" action="samePage.php" method="post">
    <select id="mySelection" name="mySelection" onChange="$('#myForm').submit();">
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="mercedes">Mercedes</option>
      <option value="audi">Audi</option>
    </select>
    </form>
    

    and you modify the query in the php to filter by the selected value:

    $sql = mysql_query(  
                          "
                          SELECT *
                          FROM TableName
                          where ColumnName like '%" . mysql_real_escape_string($_POST['mySelection']) . "%'
                  ORDER BY something ASC
                          "
                         );
    

    I didn’t test the code, but you should get the idea from here. And i assumed you use jquery for the $(‘#myForm’).submit() script.

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

Sidebar

Related Questions

Hello I have some HTML that looks like this, <div id=music_interests> <ul class=interests> <li
I have a .php file that looks like this: foreach($stmt->fetchAll() as $array) { echo
I have a page with some very basic examples that use HTML/CSS/JavaScript. I'd like
Ok I have about 12 pages included in a php page that look like
i have a php page that contains a table which i want to display
Let's assume that we have a PHP class Page , which generates PHP Page
I currently have a page setup like this: PHP Variable Declarations HTML header, then
I currently have a page setup like this: PHP Variable Declarations HTML header, then
I have a url structure that looks something like some_page.php?id=123 and I get the
I have some jquery/php interaction set up on a page. It submits some data

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.