Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:33:30+00:00 2026-06-13T07:33:30+00:00

I have an assignment that has a form that takes ID and Last name

  • 0

I have an assignment that has a form that takes ID and Last name as inputs. I want to take both the ID and Last Name and match it with the text file. If it matches, show that student in a table. If it doesn’t match, echo that the student isn’t found. So far, I got almost everything done, but everytime I search a student that exists, the student that isn’t found is echoed.

Here is the link to my form: http://hills.ccsf.edu/~ryan/a7p1.php

Here is the class of students that you can get the ID and Last name from. The first column is the Student ID and the second column is the Last Name: http://fog.ccsf.edu/~tboegel/showclass.php

Here is the code:

<?php                                                                                                                      

$lname = $_REQUEST['lname'];                                                                                               
$id = $_REQUEST['id'];

function DisplayRow($ID) {                                                                                                 
    print "<tr>\n";
    $parts = split(":", $ID);                                                                                              
    for($i=0; $i <=7; $i++) {                                                                                              
    print "<td>$parts[$i]</td>\n";                                                                                     
    }
    print "</tr>\n";                                                                                                       
}

$handle = fopen("class.txt", "r");                                                                                         
$line = fgets($handle);
while(!feof($handle)) {                                                                                                    
    $part = explode(":", $line);                                                                                           
    if($id == $part[0] && $lname == $part[1]) {                                                                            
        echo "<table border='1' width='95%'>                  
        <tr>                                                                                                               
          <th>Student ID</th>                                                                                                
          <th>Student Last Name</th>                                                                                         
          <th>Student First Name</th>
          <th>Midterm 1</th>                                                                                                 
          <th>Midterm 2</th>
          <th>Midterm 3</th>
          <th>Final Exam</th>                                                                                                
          <th>Letter Grade</th>
        </tr>";
        DisplayRow($line);
    } else {
        print "The person you are trying to search for does not exist";
        die;
    }
    $line = fgets($handle);
}
fclose($handle);
print "</table>\n";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:33:31+00:00Added an answer on June 13, 2026 at 7:33 am

    the while seaches till it finds something then it breaks…
    if the eof is reached it will trigger an error

    <?php                                                                                                                      
    
    $lname = $_REQUEST['lname'];
    $id = $_REQUEST['id'];
    
    function DisplayRow($ID) {
        print "<tr>\n";
        $parts = split(":", $ID);
        for($i=0; $i <=7; $i++) {
            print "<td>$parts[$i]</td>\n";
        }
        print "</tr>\n";
    }
    $found = false;
    $handle = fopen("class.txt", "r");
    $line = fgets($handle);
    while(!feof($handle)) {
        $part = explode(":", $line);
        if($id == $part[0] AND $lname == $part[1]) {
         echo "<table border='1' width='95%'>
            <tr>
                <th>Student ID</th>
                <th>Student Last Name</th>
                <th>Student First Name</th>
                <th>Midterm 1</th>
                <th>Midterm 2</th>
                <th>Midterm 3</th>
                <th>Final Exam</th>
                <th>Letter Grade</th>
            </tr>";
    
            DisplayRow($line);
    
            echo "</table>";
            $found = true;
            break; //no need to go further already found the data
        }
        $line = fgets($handle);
    }
    if($found == false) {
        echo "The person you are trying to search for does not exist";
    }
    fclose($handle);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment that has asked me to copy a file using buffered
I'd like to have the following. Imagine you have a homework assignment that has
I have an assignment that wants me to write an ternary search algorithm and
I have an assignment that simulates a dice game. As part of the program,
I have quite a large XSL document for an assignment that does a number
My assignment requires that I have an ER diagram that shows the dependencies between
For a school assignment I have to create a C++ program that will create
For an assignment in college, we have to make a script in Perl that
Good day, Stack Overflow. I have a homework assignment that I'm working on this
I have an object Foo that has an NSNumber property which is declared like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.