Have a problem to search between date and calculate some numbers


after i make the change ; and this is how show me the resul.

Is all of the code you posted at the beginning the entire page? You never check for buttons pressed correctly. You do not even show checking if the form was posted. This sections runs no matter which button is pressed.

And, your submit button for SearchDate does not have any name assigned to it. Hard to handle it.
I think you need to learn how to process forms in PHP. Here is a super short explanation…

//  Check if form is posted by user
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //  Now check for all buttons and handle the one submit that was pressed
    if (isset($_POST["SearchDate"]) {
        //  The user pressed the SearchDate Button.  Get the two dates and process
    ...   Here is where the two dates would be read and handled
    } elseif (isset($_POST["suma"]) {
        //  The user pressed the Sum button.  Handle that data process here
    ...   Here is where you would process the totals.
    }

Now, with that said, let’s look at your logic a little. If you display all of the totals in the grid for the dates selected, you can keep running totals while you are displaying them and display the totals at the bottom.
There is no real reason to have a separate SUM command. I would assume you want to always total the values every time you select a date range. Does this not make sense?

Because you are looping over the result from the query, immediately after the query has been executed, here -

        while ($resul=mysqli_fetch_array($quer))
        {
            echo $resul['date'].$resul['food_and_drinks'].$resul['salary'].$resul['insurance'].$resul['gas'].$resul['current'].$resul['water'].$resul['unexpected_expense'];
        }

when you get to the main code inside the html document to display the actual output, there’s nothing to loop over.

So, the question becomes, if that first while(){} loop is there for debugging purposes, why don’t you just remove it so that the main code will have something to loop over?

The whole form is called cost statements and the idea is that when the user enters he can check what expenses have been incurred and on what date. So when he enters, all the information appears. By searching by date, they select a certain period of time and the suma button is desired by the user. As I said, this is a simple reference that I can’t handle, because as you understand, I am NOT a programmer and I need help.

damm it work

now it remains to add the “suma” button and another form where there is a small problem with the while loop and everything is done

Glad you solved it! See you in your next post!

Thank you for the help well now that’s left is to make button "suma " to work

I would not use that button. Just sum up all the data for each line as you display it.
( Just sum up all them every time the dates are updated. )

yes i will try thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service