How to hide data in a table according to status

Asked

Viewed 71 times

0

I have a code that searches the data in the database and prints on the screen a table. My table that appears on the user screen has the fields:

  Referência    | Abertura  |Status     |Objeto

Reference is an ID, Open is a date and time, Status is a string and Object is a text.

This table above, search the database the "notices" registered by the administrator, in another screen. In this screen of the registration of notices, I made another table in the database that records the status that was and the status that became and to show and print on the screen when the user(Adm) makes a change of Status.

In the table that prints(above) the data that user needs to know, I need the Status to disappear from that table after 30 days when it is changed to Unsuccessful or Revoked.

How were two tables in the bank, different, when I did the select i had to do a sub-select to bring the status data changed and the date of the last change.

After that I made one if to test if the status changed has date less than 30 days from today but did not work this way:

  // $dados um mysql_fetch_array com o dados do select que eu fiz //


   if ( ( $dados['status_alterado'] === "Sem Sucesso") && ( $dados['data'] <= date("m-d-Y") - 30) ) {

       echo 'olar';
  }
  else {
      echo 'oi';
  }

I did exactly that if, but he always falls in else, i already changed in the bank a data I entered as test today 25/03/2015 for 25/01/2015, but even so the if jumps to the else.

  • Put the diagram of the table and some results, so we have how to see the data and understand how to correct the date function

  • That one if has syntax problems in parentheses. I think it should be if (($dados['status_alterado'] === "Sem Sucesso") && ($dados['data'] <= date("m-d-Y") - 30)) {. Besides date("m-d-Y") - 30) is confused, what do you want to do with that comparison? take 30 days to date? or 1 month? however that is not the way. Explain a little better so we can help more.

  • my correct if is this: [link] if ( ($notices['status'] == "Unsuccessful") && ($notices['data'] + 30 <= date("Y-m-d"))

1 answer

0


To compare dates, you need to do something like this:

if (strtotime($dados['data']) <= strtotime('-30 days')) {
    echo 'mais de 30 dias';
} else {
    echo 'menos de 30 dias';
}

Here’s an example on Ideone. Also, as stated, you need to check the syntax in relation to the parentheses.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.