Create current month searching array

Asked

Viewed 59 times

-1

I’m creating a list of birthday students of the month, using php and mysqli.

I’m not only able to load the birthday students of the current month,;

SELECT * FROM `student` WHERE MONTH(STR_TO_DATE(birthday, '%d/%m/%Y')) = MONTH(NOW())

That returns me correctly the students of the current month:

inserir a descrição da imagem aqui

Already in PHP loads all students!*

Code used:

$students = $this->db->get('student')->result_array();
foreach ($students as $row):

My difficulty is to create the array seeking only birthday students of the month from the student table Birthday field.

Current value of the array: inserir a descrição da imagem aqui

  • What value of arrays?

  • I am using <?php echo date(’d', strtotime(str_replace("/", "-",$Row['Birthday'])); ? > to show only the day.

  • Array is loading all students! I’ll add an image.

  • @Pedropaulo would not be easier you create a View in the bank and then only display the result on the page ?

  • Data is a varchar at the bank?

  • @rray, that’s right.

  • I have a rather complicated suggestion: $test = explode("/", $row["birthday"]); if (test[1] == "07") {echo row["birthday"]}&#xA; You could validate if it was the current month in php.

  • 1

    You can do the same query see => https://www.codeigniter.com/user_guide/database/query_builder.html .

  • @rray! Good, now I’ll see if I can create Row.

Show 4 more comments

1 answer

2


Try this:

$where = "MONTH(STR_TO_DATE(birthday, '%d/%m/%Y')) = MONTH(NOW())";
$this->db->where($where);
$students = $this->db->get('student')->result_array();
foreach ($students as $row):
  • 1

    You tested it before?

  • It worked perfectly! Thank you very much @Victor Carnival.

  • Thanks also @rray! By the link shared, I will give a studied.

  • Give nothing! I’m happy to help you!

Browser other questions tagged

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