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:
<?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);
if (isset($_GET['classid'])) { $classid = intval($_GET['classid']); $classinfo = classGetClassById($id);
$classname = $classinfo['name'];
$_SESSION['LAST_CLASSID'] = $classid;
$_SESSION['LAST_CLASSNAME'] = $classname;
}
page_header();
page_menu();
if (isset($_GET['success'])) { 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>
<?php if ($success) echo "<strong class=\"success\">$success</strong>"; ?>
<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);
}
if (empty($classlist)) { // no classes ?>
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);
}
if (!empty($classlist)) { ?>
<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)
echo '<tr class="even">'; else
echo '<td rowspan="15">' . $class['name'] . '</a></td>';
$przedmiotlist = classGetPrzedmiotyById($id);
if (!empty($przedmiotlist)) { $i = 0;
foreach ($przedmiotlist as $przedmiot)
{
$i++;
$przedmiotinfo = przedmiotGetPrzedmiotById
(intval($przedmiot['przedmiotid'])); if ($i % 2
) echo '<tr class="even">'; else echo '<tr class="odd">'; 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);
if (isset($_GET['success'])) $success = success
('Oceny', $_GET['success']);
if (!isset($_POST['classid'], $_POST['przedmiotid'])) { if (!isset($_GET['id'])) // coming from home // missing stuff
}
page_header();
page_menu();
if (!isset($_GET['id'])) {
// stuff all the class info into this array
$classid = intval($_POST['classid']); $classinfo = classGetClassById($classid);
} else {
$przedmiotid = intval($_GET['przedmiotid']); $classid = intval($_GET['classid']); $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>
<?php if ($success) echo "<strong class=\"success\">$success</strong>"; ?>
<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);
if (empty($studentlist)) { ?>
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++;
$studentinfo = studentGetStudentById
(intval($student['studentid'])); if ($i % 2)
echo '<tr class="even">'; else
echo '<td>'. $student['studentid'] .'</td>'; echo '<td>' . $studentinfo['lastname'] . '</td>'; echo '<td>' . $studentinfo['firstname'] . '</td>';
$query = 'SELECT studentid, przedmiotid, marks FROM '._MARKS_DB_TABLE.' WHERE
studentid='.$studentid.' AND marks = "'.$marks.'" LIMIT 1';
//
$marks = explode("|", $row['marks']); //
for($j=1; $j <= 11 $j++)
?>
<td><input type="text" name="marks[]" maxlength="2" size="3" class="inputbox" value="
<?php if(isset($marks[$i])) echo $marks[$i];?>" ></td>';
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']);
if (!isset($_POST['classid'], $_POST['przedmiotid'])) { }
$przedmiotid = $_POST['przedmiotid'];
$id = intval($_POST['classid']);
$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."' "; }
}
header('Location: /oceny/index.php?success=2'); ?>
Gdyby ktoś wiedział gdzie popełniłem błąd to bardzo proszę o pomoc w uruchomieniu tego wszystkiego.