I thought i was finish with this post, but i got another problem with the script. Adding the code from tsinka to my script worked great, but now my results keeping looping the dates.
HERE IS MY FULL CODE NOW.
$_GET['month'] = intval($_GET['month']);
$_GET['year'] = intval($_GET['year']);
$nid = $_GET['nid'];
if ($_GET['month'] != "" AND $_GET['year'] != "") {
$query = "SELECT * FROM attendance WHERE MONTH(attend_date) = {$_GET['month']} AND YEAR(attend_date) = {$_GET['year']} AND studentid = '$nid' ORDER BY attend_date DESC;";
$result = mysql_query($query);
$num = mysql_numrows($result);
$query2 = "SELECT COUNT(*) FROM attendance WHERE MONTH(attend_date) = {$_GET['month']} AND YEAR(attend_date) = {$_GET['year']} AND studentid = '$nid';";
$result2 = mysql_query($query2) or die(mysql_error());
while ($row=mysql_fetch_assoc($result)) {
$attend_date = stripslashes($row['attend_date']);
$pre_abs = stripslashes($row['pre_abs']);
$attend_option = stripslashes($row['attend_option']);
$day = date("d", strtotime($attend_date));
$month = date("m", strtotime($attend_date));
$year = date("Y", strtotime($attend_date));
$Values = array();
$Values[] = $day;
//reset($Values);
//sort($Values);
// Get the first day of the month
$month_start = $month."-"."1"."-".$year;
// determine how many days are in the last month.
if($month == 1){
$num_days_last = cal_days_in_month(0, 12, ($year -1));
} else {
$num_days_last = cal_days_in_month(0, ($month -1), $year);
}
// determine how many days are in the current month.
$num_days_current = cal_days_in_month(0, $month, $year);
// Build an array for the current days
// in the month
for($i = 1; $i <= $num_days_current; $i++){
$num_days_array[] = $i;
//echo "$i<br>";
}
$arrDaysNotPresent = array_diff($num_days_array, $Values);
$totpresent = count($Values);
echo "<b>$totpresent day(s) present</b><br><br>";
// present days:
foreach ($Values as $Day) {
echo $Day.",";
}
echo "<br><br>\n";
$totabsent = count($arrDaysNotPresent);
echo "<b>$totabsent day(s) absent</b><br><br>";
// absent days:
foreach ($arrDaysNotPresent as $Day) {
echo $Day.",";
}
}
}
WHEN I RUN THIS SCRIPT AND MY DATABASE HAS 1 DATE FOR MONTH JULY IT OUTPUTS THIS:
1 day(s) present
15,
27 day(s) absent
1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23,24,25,26,27,28,
AND WHEN MY DATABASE HAS 2 DATES FOR MONTH JULY IT OUTPUT THIS:
1 day(s) present
23,
30 day(s) absent
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,1 day(s) present
03,
62 day(s) absent
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
DOES THIS PROBLEM HAS TO DO WITH THE WHILE LOOP, PLEASE HELP ME.