Jump to content

While Loop for student attendance


tha_ripmasta

Recommended Posts

Hello

 

I created a search script to find student attendance from my db. The search works fine and I get the right results.

 

But what i'm trying to do is get the results to display like this:

 

-----------------------------------------

 

Student1 name - Student1 lastname

 

Month

 

day1, day2, day3

 

-----------------------------------------

 

Student2 name - Student2 lastname

 

Month

 

day1, day2, day3

 

--------------------------------------------

 

 

But i can't seem to figure out the right way to loop the results

 

 

Can anyone please help me and if you need more info or code ..let me know.

 

 

Here is my search code.

 

<?PHP

if ($_GET[p] == search){
                
                $ses_organization= $_SESSION['organization_id'];
                
                $Limit = 20; //Number of results per page
                
                
                // get search choices
                
                $SearchAttendance=$_POST["search_attendance"];
                if ($SearchAttendance == "") $SearchAttendance=$_GET["SearchAttendance"];
    
                $SearchStudentid=$_POST["studentid"];
                if ($SearchStudentid == "") $SearchStudentid=$_GET["SearchStudentid"];
                
                $SearchMonth=$_POST["month_att"];
                if ($SearchMonth == "") $SearchMonth=$_GET["SearchMonth"];
                
                $SearchYear=$_POST["year_att"];
                if ($SearchYear == "") $SearchYear=$_GET["SearchYear"];
                
                $SearchDate=$_POST["attendance_date"];
                if ($SearchDate == "") $SearchDate=$_GET["SearchDate"];
                
                $SearchDate2=$_POST["attendance_date"];
                if ($SearchDate2 == "") $SearchDate2=$_GET["SearchDate"];
                
                $page=$_GET["page"]; //Get the page number to show
                If($page == "") $page=1; //If no page number is set, the default page is 1
                
                
                // query
                
                $query= "Select * from attendance WHERE organization_id='$ses_organization' AND ";
                if ($SearchStudentid !=""){
                $query .= "studentid ='$SearchStudentid' AND ";
                }
                if ($SearchMonth !=""){
                $query .= "MONTH(attend_date) ='$SearchMonth' AND ";
                }
                if ($SearchYear !=""){
                $query .= "YEAR(attend_date) ='$SearchYear' AND ";
                }
                if ($SearchDate !=""){
                
                $changedate_act_search="$SearchDate";
                list($month_act,$day_act,$year_act) = split('[-./]', $changedate_act_search);
                $SearchDate=$year_act."-".$month_act."-".$day_act;
                
                $query .= "attend_date ='$SearchDate' AND ";
                }
                if ($SearchAttendance !=""){
                $query .= "attend_option = '$SearchAttendance' AND ";
                }
                
                $query2 = substr($query,0,-4);
                
                $SearchResult=mysql_query("$query2") or die(mysql_error());
                $NumberOfResults=mysql_num_rows($SearchResult);
                
                //Get the number of pages
                $NumberOfPages=ceil($NumberOfResults/$Limit);
                
                $SearchResult=mysql_query("$query2 order by attend_date ASC LIMIT " . ($page-1)*$Limit . ",$Limit") or die(mysql_error());
                
                echo "<p align='left'><span class='stepprocess'>  Search Results</span> for Activity</p>";
                
                echo "<p align='left'>     Total Results ($NumberOfResults)</p>";
                
                if ($NumberOfResults == 0)
                { echo "<br><br><center><font class=\"redtext\">0 Results Were Found!</font></center>";
                } else {
                
                $Values1 = array();
                
                while ($row = mysql_fetch_assoc($SearchResult)) {
                
                $attendance_date=$row["attend_date"];
                
                $day = date("j", strtotime($attendance_date));
                $month = date("m", strtotime($attendance_date));
                $year = date("Y", strtotime($attendance_date));
                
                $Values1[] = $day;
                
                // get students names
                $querystudent = "select * from students where student_id ='$SearchStudentid' AND organization_id='$ses_organization' AND status='1'";
                $resultstudent = mysql_query($querystudent) or die(mysql_error());
                
                $rowstudent=mysql_fetch_array($resultstudent);
                
                $student_id=$rowstudent["student_id"];
                $student_first_name=stripslashes($rowstudent["student_first_name"]);
                $student_last_name=stripslashes($rowstudent["student_last_name"]);
                
                //$changedate_act="$attendance_date";
                //list($year_act,$month_act,$day_act) = split('[-./]', $changedate_act);
                //$timestamp_act=$month_act."-".$day_act."-".$year_act;
                
                //}
                
                echo "<table width='545'  border='0' cellspacing='3' cellpadding='5' bordercolor='#CCCCCC'>";
                echo "<tr>";
                echo "<td width='100%' align='left' valign='top'><span class='links_2'><a href='?id=students&&p=student&&nid=$student_id'>$student_last_name, $student_first_name</a></span><p>";
                echo "$day, ";
                
                //foreach ($Values1 as $Day_general) {
                //echo "$Day_general ,";
                //}
                
                echo "</p></td>";
                echo "</tr>";
                echo "</table>";
                
                }
                
                //Create and print the Navigation bar
                echo "<table width=\"545\" border=\"0\" cellspacing=\"3\" cellpadding=\"5\">";
                echo "<tr>";
                echo "<td align=\"left\" valign=\"top\">";
                   
                $Nav="";
                If($page > 1) {
                $Nav .= "<span class='links_2'><A HREF=\"?id=searchdb_attendance&&p=search&&page=" . ($page-1) . "";
                
                if ($SearchStudentid !=""){
                $Nav .= "&SearchStudentid=" .urlencode($SearchStudentid) . "";
                }
                if ($SearchMonth !=""){
                $Nav .= "&SearchMonth=" .urlencode($SearchMonth) . "";
                }
                if ($SearchYear !=""){
                $Nav .= "&SearchYear=" .urlencode($SearchYear) . "";
                }
                if ($SearchDate !=""){
                $Nav .= "&SearchDate=" .urlencode($SearchDate2) . "";
                }
                if ($SearchAttendance !=""){
                $Nav .= "&SearchAttendance=" .urlencode($SearchAttendance) . "";
                }
                
                $Nav .= "\"><< Previous</A></span>";
                
                }
                ELSE {
                $Nav .="Previous";
                }
                For($i = 1 ; $i <= $NumberOfPages ; $i++) {
                $Nav .=" | ";
                If($i == $page) {
                $Nav .= "Page $i";
                }Else{
                $Nav .= "<span class='links_2'><A HREF=\"?id=searchdb_attendance&&p=search&&page=" . $i . "";
                
                if ($SearchStudentid !=""){
                $Nav .= "&SearchStudentid=" .urlencode($SearchStudentid) . "";
                }
                if ($SearchMonth !=""){
                $Nav .= "&SearchMonth=" .urlencode($SearchMonth) . "";
                }
                if ($SearchYear !=""){
                $Nav .= "&SearchYear=" .urlencode($SearchYear) . "";
                }
                if ($SearchDate !=""){
                $Nav .= "&SearchDate=" .urlencode($SearchDate2) . "";
                }
                if ($SearchAttendance !=""){
                $Nav .= "&SearchAttendance=" .urlencode($SearchAttendance) . "";
                }
                
                $Nav .= "\">Page $i</A></span>";
                }
                }
                If($page < $NumberOfPages) {
                $Nav .= "  | <span class='links_2'><A HREF=\"?id=searchdb_attendance&&p=search&&page=" . ($page+1) . "";
                
                if ($SearchStudentid !=""){
                $Nav .= "&SearchStudentid=" .urlencode($SearchStudentid) . "";
                }
                if ($SearchMonth !=""){
                $Nav .= "&SearchMonth=" .urlencode($SearchMonth) . "";
                }
                if ($SearchYear !=""){
                $Nav .= "&SearchYear=" .urlencode($SearchYear) . "";
                }
                if ($SearchDate !=""){
                $Nav .= "&SearchDate=" .urlencode($SearchDate2) . "";
                }
                if ($SearchAttendance !=""){
                $Nav .= "&SearchAttendance=" .urlencode($SearchAttendance) . "";
                }
                
                $Nav .= "\">Next >></A></span>";
                }
                
                Echo "<BR><BR>" . $Nav;
                
                echo "</td></tr></table>";
                
            /*echo "<table width='545'  border='0' cellspacing='3' cellpadding='5'>";
                echo "<tr><td align=\"left\"><a href=\"search_reports/print_search_activity.php?SearchString=$SearchString&&SearchType=$SearchType&&org=$ses_organization\" target=\"_blank\"><img src=\"images/printer.gif\" border=\"0\" alt=\"Print\"></a></td><td align=\"right\">[ <a href=\"javascript:history.go(-1)\">Go back</a> ]</td></tr>";
                echo "</table>";*/
                
                }
                } 
?>

Link to comment
https://forums.phpfreaks.com/topic/45423-while-loop-for-student-attendance/
Share on other sites

$query="SELECT * FROM studends order by student_name ASC  ";
$result=mysql_query($query);

while ($row = mysql_fetch_assoc($result))
       $display_data[] = $row;
}
echo "<pre>";
print_r($display_data);

for($i=0;$i<count($display_data);$i++){
        echo $display_data[$i]['student_name '];
..........
.........
.........
.........
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.