This creates an array with one date in it. You should create the empty array before the for() is processed like this: $mondatesarr = array(); This will create the array with no data inside it. Then, instead of creating the one array entry ( $mondatesarr = array($mondates); ) replace it with adding one date to the array like this: array_push($mondatearr, $mondates); This command pushes a new value at the end of the array. Here is a page that explains it. Array_Push Info
Now, that should create an array for you that holds all your Mondays. I did note in the code you posted, you did not end your FOR() loop. A FOR loop is like for($i = 1; $i<= $days; $i++){ some code } I did not see your closing brace which should be around where the ///// comment was above.
Next, to fix the query issues…
First, MySQL is outdated and seldom used at all now. The newer version MySQLi is needed. A lot of schools teach the old outdated versions as they still have textbooks with that version. You should update your MySQL code to the MySQLi versions. The “i” stands for improved. It is a much more secure version and actually is faster too. But do it after you get this working. Here is a link listing each MySQLi commands and they show how to set each up. W3Schools MySQLi commands
Comparing dates inside a query sometimes is tricky. You are creating an array of dates formatted as Y-m-d as they are held in a MySQL database. If the field you are using is set up as a “DATE” type of field or even if it is a “DATETIME” type of field, you can use DATE(fieldname) in the query to format the field for just the date part. Then, you can use the IN() function for your array and it should work well. You would need to change the query something like this:
SELECT * FROM calendar WHERE DATE(startTime) = '2010-04-29'
As you see, you can pull out the “Y-m-d” format inside of a query using DATE() function. So, using that way, you would change your query to using the IN() function differently. I thought you would look at the MySQL function IN() and learn it. But, to explain here, the IN() needs a list of dates such as IN(‘2018-08-24’, ‘2018-08-28’) etc… To use a PHP array inside the MySQL query, you need to format the data inside the array into a series of strings. To do this with your code, change your query like this:
$selectvalidsplmonmumls = “Select count(*) from pin_mls_detail
where ( brkmu_no
= ‘M’ OR brkmu_no
= ‘1’ OR brkmu_no
= ‘1F’ ) AND pin_pin
= ‘$pinid’ AND date_pin IN(" . implode( ‘,’, $mondatesarr) . ")”;
As you see, using the PHP function IMPLODE() we create an output that is the list of dates. Then we place this inside your query inside the IN() function. The query then has the list of dates inside the query where they should be. Hope that makes sense to you.
Also, this code will get all the Mondays of the current month:
$date = new DateTime('first Monday of this month');
$thisMonth = $date->format('m');
while ($date->format('m') === $thisMonth) {
array_push($mondatesarr, $date->format('Y-m-d'));
$date->modify('next Monday');
}
Date time was Gregorian, so you are in Russia. Nice! Always wanted to visit there!