mtaylor2 0 Newbie Poster

Hi All,

I have a form that shows the list of expenses based on which category you choose from the select box. I then have links above this which allows the user to view expenses in 1st, 2nd, 3rd or 4th quarter.

If I select a Category and then view expenses it shows all expenses as planned however, if I then click on 1st quarter it wipes the current expenses listed and I have to reselect the category and then it lists 1st quarter expenses for that category. How can I just select a category and then click between 1st,2nd,3rd or 4th quarter and show the results.

Heres my code, I hope I made some sense...

ViewExpenseScript.php

<?php    

$expCat = $_POST['expCat'];

    if( $_GET['Date'] == '1stQuarter' ){
        $query = mysql_query("SELECT * FROM `db` WHERE (Category = '$expCat' AND Date >= '20100101' AND Date <= '20100331')ORDER BY Date");
        
        echo"<form method='post' action='viewExpenseScript.php?Date=1stQuarter'>";
    }
    else if($_GET['Date'] == '2ndQuarter' ){
        $query = mysql_query("SELECT * FROM `db` WHERE (Category = '$expCat' AND Date >= '20100401' AND Date <= '20100630')ORDER BY Date");
        echo"<form method='post' action='viewExpenseScript.php?Date=2ndQuarter'>";
    }
    else if($_GET['Date'] == '3rdQuarter' ){
        $query = mysql_query("SELECT * FROM `db` WHERE (Category = '$expCat' AND Date >= '20100701' AND Date <= '20100930')ORDER BY Date");
        echo"<form method='post' action='viewExpenseScript.php?Date=3rdQuarter'>";
    }
    
    else{
        $query = mysql_query("SELECT * FROM `db` WHERE (Category = '$expCat')ORDER BY Date");
        echo"<form method='post' action='viewExpenseScript.php'>";
    }



    echo "<H2>View expenses</H2>
    <a href='ViewExpenseScript.php?Date=1stQuarter'>1st Qtr</a> | 
    <a href='ViewExpenseScript.php?Date=2ndQuarter'>2nd Qtr</a> |
    <a href='ViewExpenseScript.php?Date=3rdQuarter'>3rd Qtr</a> | 
    <a href='ViewExpenseScript.php?Date=4thQuarter'>4th Qtr</a> |
    
    <table border='0' cellpadding='0' cellspacing='0'>
            <tr><td>Category:</td>
            <td><select name='expCat'>
                <option value='Accommodation'>Accommodation</option>
                <option value='Alcohol'>Alcohol</option>
                <option value='Automotive'>Automotive</option>
                <option value='Communications'>Communications</option>
                <option value='Clothing'>Clothing</option>
                <option value='Entertainment'>Entertainment</option>
                <option value='Fishing'>Fishing</option>
                <option value='Fuel'>Fuel</option>
                <option value='Groceries'>Groceries</option>
                <option value='Hardware'>Hardware</option>
                <option value='Laundry'>Laundry</option>
                <option value='Takeout'>Takeout</option>                
              </select>
                </td></tr>
    <tr><td><input type='submit' value='View expenses' name='expSub' /></td>
        <td><input type='reset' value='Reset' /></td></tr>
    </table> 
        
    </form>";


    while($row = mysql_fetch_array($query)){
        echo "<tr height='20px'>";
        echo "<td>".$row['newDate']."</td>";
        echo "<td>".$row['Description']."</td>";
        echo "<td>$".$row['Amount']."</td>";
        echo "</tr>";
    }

?>

I also just tried adding a session state as follow

<?php
session_start();

$expCat = $_SESSION;

which does what I want it to do for the default category = Accommodation, but then it will not show any expenses for other categories.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.