Record data once a month (Php mysql)

0

Hi, I'm doing a php application with Codeigniter and mysql. And I have a table in which you should do a single insert once a month, that is, if until today you have not registered anything you should let me do the insert, otherwise you should not leave until the first day of the next month.

Any ideas on how to do this?

    
asked by daniel2017- 16.03.2017 в 15:09
source

1 answer

0

You can do it with a query

SELECT COUNT(*) FROM tu_tabla WHERE MONTH(tu_fecha) = MONTH(NOW());

If you have your model, you can do the following

 $this->db->select('*');
 $this->db->from('tu_tabla');
 $this->db->where('MONTH(tu_fecha)', 'MONTH(NOW())');
 $query = $this->db->get();

if(empty($query->result())){
  return false;
} else {
  return true;
}

If it returns empty, in php you allow the registration, if you return data you do not allow the INSERT, this would be done with an IF, this depends on how you are programming

    
answered by 16.03.2017 в 15:12