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:
<?php include '../includes/common.inc.php'; include '../includes/klasy.inc.php'; include '../includes/students.inc.php'; include '../includes/oceny.inc.php'; require_group(_TEACHER_GROUP); $classinfo = classGetClassById($id); $classname = $classinfo['name']; $_SESSION['LAST_CLASSID'] = $classid; $_SESSION['LAST_CLASSNAME'] = $classname; } page_header(); page_menu(); if ($_GET['success'] == 1) { $success = 'Oceny zapisano pomyślnie.'; } } ?> <div id="content"> <h2>Oceny</h2> <div id="breadcrumb"><a href="<?=$conf_settings['site_url']?>">Strona główna</a> -> <em>Oceny</em></div> <div style="clear: both;"></div> <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> <?php if (authUserInGroup($_SESSION['username'], _TEACHER_GROUP)) { $classlist = classGetClassesByCreator($_SESSION['username']); // get array of classes since the beginning of time } elseif (authUserInGroup($_SESSION['username'], _ADMIN_GROUP)) { $classlist = classGetClassesAfterTime(0); } ?> W tej chwili nie ma dostępnych klas. Kliknij tutaj aby <a href="/klasy/new.php">utworzyć nową klasę</a>. <?php } else { ?> <div style="float: left;"> <p>Wybierz klasę:</p> <p> <?php if (authUserInGroup($_SESSION['username'], _TEACHER_GROUP)) { $classlist = classGetClassesByCreator($_SESSION['username']); } elseif (authUserInGroup($_SESSION['username'], _ADMIN_GROUP)) { $classlist = classGetClassesAfterTime(0); } ?> <table cellpadding=5 class="classlist"> <tr><th>Nazwa</th><th class="classlist">Przedmioty Klasy <?=$classname?></th></tr> <?php $i = 0; foreach ($classlist as $class) { $i++; if ($i % 2) else $przedmiotlist = classGetPrzedmiotyById($id); $i = 0; foreach ($przedmiotlist as $przedmiot) { $i++; echo '<td><a href="/oceny/do.php?id=' . $przedmiot['przedmiotid'] . '">' . $przedmiotinfo['przedmiot'] . '</td>'; } } else { ?> W tej chwili nie ma przedmiotów w tej klasie. Tutaj możesz <a href="addprzedmiot.php">dodać przedmiot do tej klasy</a>. <?php } } }else { ?> W tej chwili nie ma klas w bazie danych. Tutaj możesz <a href="newclass.php">utworzyć nową klasę</a>. <?php } ?> </p> </div> </p> </div> <div style="clear: both;"></div> <?php } ?> </div> <!-- content --> <?php page_footer(); ?>
kod pliku do.php:
<?php // oceny/do.php: Attendance processes include '../includes/common.inc.php'; include '../includes/klasy.inc.php'; include '../includes/students.inc.php'; include '../includes/oceny.inc.php'; require_group(_TEACHER_GROUP); // missing stuff exit; } page_header(); page_menu(); // stuff all the class info into this array $classinfo = classGetClassById($classid); } else { $classinfo = classGetClassById($classid); } ?> <div id="content"> <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> <div id="subnav"> <ul> <li> <form method="post" action="/oceny/do.php" class="search"> <label for="toyear"> <img src="/images/options/search.png"/> Przejdź do: </label> <?php dateboxes(true, false); ?> <label for="class"> Klasy: </label> <?php classSelectBox(); ?> <input type="submit" name="submit" value="Go" /> </form> </li> </ul> </div> <div style="clear: both;"></div> <p>Wpisz oceny obok każdego ucznia w postaci cyfrowej od 0 do 6 z uwzględnieniem "+" i "-".</p> <?php $studentlist = classGetStudentsById($classid); ?> W tej klasie nie ma uczniów. Aby wpisywać oceny musisz <a href="addstudent.php">dodać uczniów do tej klasy</a>. <?php } else { ?> <form method="post" action="change.php"> <table cellpadding="5" class="classlist"> <tr><th>Student ID</th><th>Nazwisko</th><th>Imię</th><th>Oceny</th></tr> <?php $i = 0; foreach ($studentlist as $student) { $absvalue = NULL; // reset $i++; if ($i % 2) else $query = 'SELECT studentid, przedmiotid, marks FROM '._MARKS_DB_TABLE.' WHERE studentid='.$studentid.' AND marks = "'.$marks.'" LIMIT 1'; // // for($j=1; $j <= 11 $j++) ?> echo '</tr>'; echo "\n"; } echo '</table>'; } ?> <input type="hidden" name="marks" value="<?=$marks?>" /> <input type="hidden" name="classid" value="<?=$classid?>" /> <input type="submit" value="Zapisz" /> </div> <!-- content --> <?php page_footer(); ?>
i w końcu kod pliku change.php
<?php include '../includes/common.inc'; include '../includes/classes.inc'; include '../includes/students.inc'; include '../includes/oceny.inc'; require_group(_TEACHER_GROUP); // if (isset($_GET['success'])) $success = success('Oceny', $_GET['success']); exit; } $przedmiotid = $_POST['przedmiotid']; $class_students = classGetStudentsById($id); foreach ($class_students as $class_student) { foreach ($student as $studentid) { $query_update = "UPDATE "._MARKS_DB_TABLE." SET `marks` = '".implode('|',$_POST['marks'])."' WHERE `id` = '".$id."' "; } } exit; ?>
Gdyby ktoś wiedział gdzie popełniłem błąd to bardzo proszę o pomoc w uruchomieniu tego wszystkiego.