Announcement

Collapse
No announcement yet.

grades 2 students

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mark Hensler
    replied
    fine..... I'll take the harder part

    This is quicky code.... meaning it's untested.
    Someone plz proof.

    [fake file]
    section 1,123-45-6789,a
    section 2,928-54-7669,c
    section 3,715-48-7521,b
    [/fake file]

    PHP Code:
    // create DB connection
    // somewhere up here

    // update path to your file
    $data_file "/path/to/fake_file.txt";

    // open and read file into an array
    $filefile($data_file);

    // loop through the lines
    for ($i=0$i<=count($file); $i++) {
       
    // get the data from the line
       
    list($section,$id,$grade) = split(",",$file[$i]);
       
       
    // shove the data into the DB
       
    $query "INSERT INTO grades (section, id, finalgrade) VALUES('$section','$id','$grade')";
       
    $result mysql_query($query);
       
       
    // did it get in the DB successfully?
       
    if (!$result) die("\n<BR>\nQuery Error: $query\n<BR>\n");

    Leave a comment:


  • krs-one
    replied
    here is a more complete look

    If you have your mysql database set up like so:

    Table: grades

    [CODE]
    +---------------+----------------+
    | id | 1 |
    | ssnumber | 123456 |
    | grade | 98 |
    +----------------+---------------+
    [CODE}

    Then you can select data from it like so:

    PHP Code:
    $sql "SELECT * FROM grades WHERE id=$id"// id is a value from a field
    $result mysql("database",$sql) or die("failed to issue query");
    $numrows mysql_num_rows($result); // not always necessary, only if retreiving more than one row, in this case, we are not

    for($i=0$i<$numrows$i++) {
       
    $id mysql_result($result,$i,"id"); // grab the id
       
    $ss mysql_result($result,$i,"ssnumber"); // grab the ss number
       
    $grade mysql_result($result,$i,"grade"); // grab the grade
       
    print "$id - $ss - $grade<br>\n";

    The for() loop is only necessary if you have more than one row, and in this case you don't. In this case, you could have also taken out the $i and replaced it with a 0 for the mysql_result() calls.

    Hope this helps.

    -Vic
    Last edited by krs-one; Fri 15 Jun '01, 8:17pm.

    Leave a comment:


  • Theiggsta
    replied
    the main mysql query you shoudl be using is:

    SELECT * FROM grades WHERE id = '$studentid'

    So when submitting a form, use the ID your lookign for as the variable, and it will pull up the entire Row record for all matching ID #'s

    Leave a comment:


  • Shoe
    started a topic grades 2 students

    grades 2 students

    I'm wanting to give grades to my students. I have created an empty database called grades. I want to create a table with 3 items: section, id(ss#), finalgrade.

    How do I write php code to retreive the grade based on id?

    BTW I have the data as an ascii text: section, SS#, finalgrade format one record per line.

    How do I create the table and load it with the data in the ascii file?

    Can I do this with php?
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X