matching values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    matching values

    hello,

    im trying to make an attendance record. im using a form where im entering two values,

    1. Date
    2. Absent Students

    im entering roll numbers of the absent students separated by "-" like this: 5-10-15-20-21-23. these roll numbers are then stored into a mysql database in the same format. now there are all 50 students which are stored in a different table. i just want to match these roll numbers who are absent against all 50 students. if the roll number is there in the absent students then it will not be inserted else it will be inserted into a different field named as present in the same table in the same format as 1-2-3-4-6-7-8-9-11. the roll number which is appeared in the absent will not be appeared in this field. im using explode to make an array of roll numbers which are entered in the form. following is what im doing:

    Code:
     extract($_POST);
        
        $selectStudent = $this->database->Query("select * from students");
        $strStudentAbsent = explode("-", $strAbsent);  
        while($result = mysql_fetch_assoc($selectStudent)){  
        foreach($strStudentAbsent as $a){
          $a = (int)$a;
             
            if($result['rno']<>$a){
                echo $result['rno']."Present <br />";
            } else{
                
                echo $result['rno']."Absent <br />";
                
            }
        }
        
        }
    rno = roll number of the students

    please tell me how i can do this. thanx
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    So you have a form and two tables.

    You get a list of student IDs that were absent that day from the form.

    You compare it to one of the tables which has the set of all students.

    What you're trying to do is put all the students that were present into a field in the second table, then put the ones that were absent into another field in this second table also.

    Do I understand you correctly?



    Dan

    Comment

    • prabirchoudhury
      New Member
      • May 2009
      • 162

      #3
      I ma bit lost about what is your question ? could you put in details what part you are having problem with. your logic and code above that comparing the absent student should work fine.

      :))

      Comment

      • mfaisalwarraich
        New Member
        • Oct 2007
        • 194

        #4
        ok thanx for both of you to reply.

        let me elaborate my problem again. I have a form where i need to enter the roll numbers of students who are absent on that day.

        the form is something like this:

        Code:
        <table cellpadding="8" cellspacing="3" border="1" align="center">
        <form method="post"  >
        <tr><td>Date: </td><td><input type="text" name="strDate" /></td></tr>
        <tr><td>Absent Students </td><td><input type="text" name="strAbsent" size="100" /></td></tr>
        
        <tr><td colspan="2" align="center"><input type="submit" value="Enter Attendance" name="submit" /></td></tr>
        </form>
        </table>
        there are two fields in the form:

        Date: 25-jun-2009
        Absent Students: 5-10-15-22-28

        I have a table where i have saved all students with their roll numbers. what im trying to do is im saving absent students and date in other table in the same format they are entered in the form like date as: 25-jun-2009 and absent students as 5-10-15-22-28 (5 students with different roll numbers). my logic is if i know the students who are absent then i dont need to save students who are present at dat day. i just want to list the student who were present at dat day.

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          I haven't tried this but maybe something like:

          Code:
           
           extract($_POST); 
            
              $selectStudent = $this->database->Query("select * from students"); 
              $strStudentAbsent = explode("-", $strAbsent);   
              while($result = mysql_fetch_assoc($selectStudent)){
               if( in_array( $result['rno'], $strStudentAbsent ) ) {
                      echo $result['rno']." - Absent <br />";
                  } else {
                      echo $result['rno']." - Present <br />";
                  }
               }
          Using the in-array() function.

          Comment

          • prabirchoudhury
            New Member
            • May 2009
            • 162

            #6
            matching values

            your logic would work fine but i could give you another way to do that. when i saw your attandance table that interface and loogic bit different from what i am thinking, I have added an interface that might help to make sense.

            1. puall all the student roll name with paper detail and date, attendant, paper and semister
            2. check box agenst each student to make the attendance (check if present).
            3. submit that list to the attendance table with student_id, paper_id, date, semister, attendant_id

            Code:
            <table cellpadding="8" cellspacing="3" border="1" align="center" width=500> 
            <form method="post"  > 
            <tr>
            	<td>Date: </td>
            	<td><? echo date('d-m-Y');?></td>
            	<td>Subject: PHP Development</td>
            </tr> 
            <tr bgcolor=#a9b0b6>
            	<td>Roll no </td>
            	<td>Stdent Name </td>
            	<td>Make Attendance </td>
            </tr> 
            <tr>
            	<td>1 </td>
            	<td>Bob dick </td>
            	<td><input type="checkbox" name="roll number" > </td>
            </tr> 
            <tr>
            	<td>2 </td>
            	<td>Sam Smith </td>
            	<td><input type="checkbox" name="roll number" > </td>
            </tr> 
            <tr>
            	<td>3 </td>
            	<td>Ram Kumer </td>
            	<td><input type="checkbox" name="roll number" > </td>
            </tr> 
            <tr>
            	<td>49 </td>
            	<td>Ram dick </td>
            	<td><input type="checkbox" name="roll number" > </td>
            </tr> 
            <tr>
            	<td>50 </td>
            	<td>Ram smith </td>
            	<td><input type="checkbox" name="roll number" > </td>
            </tr> 
            <tr>
            	<td colspan="3" align="right" calspan=2><input type="submit" value="Enter Attendance" name="submit" /></td>
            </tr> 
            </form> 
            </table>


            cheers


            :)
            Last edited by Dormilich; Sep 16 '09, 05:38 AM. Reason: correcting the messed up HTML

            Comment

            • mfaisalwarraich
              New Member
              • Oct 2007
              • 194

              #7
              thanx theservant i think i was looking at the same thing :) i worked for me thanx alot. prabir thank u too for giving me ur logic. but dear if i have more than 1000 students then how i can select each and every student for their presence or absentees so in my opinion its better for me to just enter the roll of students who are absent rest of the students will be present on dat day automatically. i appreciate your help too. thank u once again.

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                No worries mate, glad to help. Let us know how you go and maybe a snippet of your final code to help others trying to do the same thing ;)

                Comment

                • prabirchoudhury
                  New Member
                  • May 2009
                  • 162

                  #9
                  thanks .. we could have more then 1000 student in one institute but not at a time in one class .

                  student --> paper --> class(s) --> class_timetable

                  year --> semester --> paper --> class.

                  teacher --> semester --> paper --> class

                  you have to make the relational database model with above tables. every class might have maximum 60 student (still depends). each class divided on stream or group. and you need to make the attendance for each individual class group. your design might work for the short term but if you think about the whole system all above database table are very important for any institute for a long term and bigger sector. all those databases are very important to generate any report on any part of the application. need to make a good architecture for a valuable system.

                  may help those in future :)

                  Comment

                  Working...