Witam
Tym razem mam problem z pobraniem danych z bazy danych.
Efekt końcowy powinien wyglądać tak:
Klasa | Przedmioty klasy
Klasa1 | Przedmiot1
| Przedmiot2
| ...
Klasa2 | Przedmiot1
| Przedmiot2
| ...
.........

Po kliknięciu na dowolny przedmiot powinno się przejść do edycji ocen w tej klasie z danego przedmiotu.
Napisałem taki kod:
  1. <?php
  2.  include '../includes/common.inc.php';
  3.  include '../includes/klasy.inc.php';
  4.  include '../includes/students.inc.php';
  5.  include '../includes/oceny.inc.php';
  6.  
  7.  require_group(_TEACHER_GROUP);
  8.  
  9.  if (isset($_GET['classid'])) {      
  10.     $classid = intval($_GET['classid']);
  11.     $classinfo = classGetClassById($id);
  12.     $classname = $classinfo['name'];
  13.     $_SESSION['LAST_CLASSID'] = $classid;
  14.     $_SESSION['LAST_CLASSNAME'] = $classname;
  15.   }
  16.  
  17.  page_header();
  18.  page_menu();
  19.  
  20.  if (isset($_GET['success'])) {
  21.     if ($_GET['success'] == 1) {
  22.        $success = 'Oceny zapisano pomyślnie.';
  23.     }
  24.  }
  25.  
  26. ?>
  27.  
  28. <div id="content">
  29. <h2>Oceny</h2>
  30. <div id="breadcrumb"><a href="<?=$conf_settings['site_url']?>">Strona główna</a> -> <em>Oceny</em></div>
  31.  
  32. <?php if ($success) echo "<strong class=\"success\">$success</strong>"; ?>
  33.  
  34. <div style="clear: both;"></div>
  35.  
  36. <p>Witaj w systemie ocen. Tutaj możesz dodawać oceny, przeglądać i edytować oceny. Wybirz klasę i przedmiot w której zamierzasz wykonać te operacje.</p>
  37.  
  38. <?php
  39. if (authUserInGroup($_SESSION['username'], _TEACHER_GROUP)) {
  40.    $classlist = classGetClassesByCreator($_SESSION['username']); // get array of classes since the beginning of time
  41. } elseif (authUserInGroup($_SESSION['username'], _ADMIN_GROUP)) {
  42.    $classlist = classGetClassesAfterTime(0);
  43. }
  44.  
  45. if (empty($classlist)) { // no classes
  46. ?>
  47. W tej chwili nie ma dostępnych klas. Kliknij tutaj aby <a href="/klasy/new.php">utworzyć nową klasę</a>.
  48. <?php
  49. } else {
  50. ?>
  51. <div style="float: left;">
  52. <p>Wybierz klasę:</p>
  53. <p>
  54. <?php
  55. if (authUserInGroup($_SESSION['username'], _TEACHER_GROUP)) {
  56.    $classlist = classGetClassesByCreator($_SESSION['username']);
  57. } elseif (authUserInGroup($_SESSION['username'], _ADMIN_GROUP)) {
  58.    $classlist = classGetClassesAfterTime(0);
  59. }
  60.  
  61. if (!empty($classlist)) {
  62. ?>
  63.  
  64. <table cellpadding=5 class="classlist">
  65. <tr><th>Nazwa</th><th class="classlist">Przedmioty Klasy <?=$classname?></th></tr>
  66. <?php
  67.    $i = 0;
  68.    foreach ($classlist as $class)
  69.    {
  70.      $i++;
  71.      if ($i % 2)
  72.       echo '<tr class="even">';
  73.      else
  74.       echo '<tr class="odd">';
  75.      echo '<td rowspan="15">' . $class['name'] . '</a></td>';
  76.      
  77. $przedmiotlist = classGetPrzedmiotyById($id);
  78.  
  79. if (!empty($przedmiotlist)) {
  80.    $i = 0;
  81.    foreach ($przedmiotlist as $przedmiot)
  82.    {
  83.      $i++;
  84.      $przedmiotinfo = przedmiotGetPrzedmiotById(intval($przedmiot['przedmiotid']));
  85.      if ($i % 2)       echo '<tr class="even">';      else       echo '<tr class="odd">';
  86.      echo '<td><a href="/oceny/do.php?id=' . $przedmiot['przedmiotid'] . '">' . $przedmiotinfo['przedmiot'] . '</td>';
  87.      echo '</tr>';
  88.      echo "\n";
  89.    }
  90.    echo '</table>';
  91. } else {
  92. ?>
  93. W tej chwili nie ma przedmiotów w tej klasie.  Tutaj możesz <a href="addprzedmiot.php">dodać przedmiot do tej klasy</a>.
  94. <?php
  95. }
  96.      echo '</tr>';
  97.      echo "\n";
  98.    }
  99.    echo '</table>';
  100. }else {
  101. ?>
  102. W tej chwili nie ma klas w bazie danych.  Tutaj możesz <a href="newclass.php">utworzyć nową klasę</a>.
  103. <?php
  104. }
  105. ?>
  106. </p>
  107. </div>
  108. </p>
  109. </div>
  110. <div style="clear: both;"></div>
  111. <?php
  112. }
  113. ?>
  114. </div> <!-- content -->
  115. <?php
  116.  page_footer();
  117. ?>


kod pliku do.php:
  1. <?php
  2.  // oceny/do.php: Attendance processes
  3.  
  4.  include '../includes/common.inc.php';
  5.  include '../includes/klasy.inc.php';
  6.  include '../includes/students.inc.php';
  7.  include '../includes/oceny.inc.php';
  8.  
  9.  require_group(_TEACHER_GROUP);
  10.  
  11.  if (isset($_GET['success'])) $success = success('Oceny', $_GET['success']);
  12.  
  13.  if (!isset($_POST['classid'], $_POST['przedmiotid'])) {
  14.      if (!isset($_GET['id']))  // coming from home
  15.      // missing stuff
  16.      exit;
  17.  }
  18.  
  19.  page_header();
  20.  page_menu();
  21.  
  22.  if (!isset($_GET['id'])) {
  23.      
  24.      // stuff all the class info into this array
  25.      $classid = intval($_POST['classid']);
  26.      $classinfo = classGetClassById($classid);
  27.  } else {
  28.      $przedmiotid = intval($_GET['przedmiotid']);
  29.      $classid = intval($_GET['classid']);
  30.      $classinfo = classGetClassById($classid);
  31.  }
  32.  
  33. ?>
  34. <div id="content">
  35. <h2>Wpisywanie ocen klasy <?=$classinfo['name']?>, z przedmiotu <?php echo $przedmiot; ?></h2><div id="breadcrumb"><a href="<?=$conf_settings['site_url']?>">Strona główna</a> -> <a href="/oceny/">Oceny</a> -> <em>Wpisywanie ocen</em></div>
  36.  
  37. <?php if ($success) echo "<strong class=\"success\">$success</strong>"; ?>
  38.  
  39. <div id="subnav">
  40. <ul>
  41.  <li>
  42.   <form method="post" action="/oceny/do.php" class="search">
  43.    <label for="toyear">
  44.     <img src="/images/options/search.png"/>
  45.     &nbsp;Przejdź do:
  46.    </label>
  47.    <?php dateboxes(true, false); ?>
  48.    <label for="class">
  49.     Klasy:
  50.    </label>
  51.    <?php classSelectBox(); ?>
  52.    
  53.    <input type="submit" name="submit" value="Go" />
  54.   </form>
  55.  </li>
  56. </ul>
  57. </div>
  58. <div style="clear: both;"></div>
  59.  
  60. <p>Wpisz oceny obok każdego ucznia w postaci cyfrowej od 0 do 6 z uwzględnieniem "+" i "-".</p>
  61.  
  62. <?php
  63. $studentlist = classGetStudentsById($classid);
  64.  
  65. if (empty($studentlist)) {
  66. ?>
  67. W tej klasie nie ma uczniów. Aby wpisywać oceny musisz <a href="addstudent.php">dodać uczniów do tej klasy</a>.
  68. <?php
  69. } else {
  70. ?>
  71.  
  72. <form method="post" action="change.php">
  73. <table cellpadding="5" class="classlist">
  74. <tr><th>Student ID</th><th>Nazwisko</th><th>Imię</th><th>Oceny</th></tr>
  75.  
  76. <?php
  77.    
  78.     $i = 0;
  79.     foreach ($studentlist as $student)
  80.     {
  81.       $absvalue = NULL; // reset
  82.       $i++;
  83.       $studentinfo = studentGetStudentById(intval($student['studentid']));
  84.       if ($i % 2)
  85.        echo '<tr class="even">';
  86.       else
  87.        echo '<tr class="odd">';
  88.        
  89.       echo '<td>'. $student['studentid'] .'</td>';
  90.       echo '<td>' . $studentinfo['lastname'] . '</td>';
  91.       echo '<td>' . $studentinfo['firstname'] . '</td>';
  92.  
  93. $query = 'SELECT studentid, przedmiotid, marks FROM '._MARKS_DB_TABLE.' WHERE
  94.    studentid='.$studentid.' AND marks = "'.$marks.'" LIMIT 1';
  95.    $result = @mysql_query($query) or die(mysql_error());
  96. //
  97. $row = mysql_fetch_array($result);
  98. $marks = explode("|", $row['marks']);
  99. //    
  100. for($j=1; $j <= 11 $j++)
  101. ?>
  102. <td><input type="text" name="marks[]" maxlength="2" size="3" class="inputbox" value="<?php if(isset($marks[$i])) echo $marks[$i];?>" ></td>';
  103.       echo '</tr>';
  104.       echo "\n";
  105.     }
  106.     echo '</table>';
  107. }
  108. ?>
  109. <input type="hidden" name="marks" value="<?=$marks?>" />
  110. <input type="hidden" name="classid" value="<?=$classid?>" />
  111. <input type="submit" value="Zapisz" />
  112. </div> <!-- content -->
  113.  
  114. <?php
  115.  page_footer();
  116. ?>


i w końcu kod pliku change.php
  1. <?php
  2.  include '../includes/common.inc';
  3.  include '../includes/classes.inc';
  4.  include '../includes/students.inc';
  5.  include '../includes/oceny.inc';
  6.  
  7.  require_group(_TEACHER_GROUP);
  8.  
  9. //  if (isset($_GET['success'])) $success = success('Oceny', $_GET['success']);
  10.  
  11.  if (!isset($_POST['classid'], $_POST['przedmiotid'])) {
  12.     header('Location: /oceny/');
  13.     exit;
  14.  }
  15.  
  16.  $przedmiotid = $_POST['przedmiotid'];
  17.  $id = intval($_POST['classid']);
  18.  
  19.  $class_students = classGetStudentsById($id);
  20.  
  21.  foreach ($class_students as $class_student)
  22.  {
  23.  foreach ($student as $studentid)
  24.  {
  25. $query_update = "UPDATE "._MARKS_DB_TABLE." SET `marks` = '".implode('|',$_POST['marks'])."' WHERE `id` = '".$id."' ";
  26. $result_update = mysql_query($query_update) or die(mysql_error());
  27. }
  28. }
  29.  
  30.  header('Location: /oceny/index.php?success=2');
  31.  exit;
  32. ?>

Gdyby ktoś wiedział gdzie popełniłem błąd to bardzo proszę o pomoc w uruchomieniu tego wszystkiego.