这是表,当用户在选择框中选择某些值时生成。如何在会话中保存此生成的表,并在每次当前用户登录时显示。
<table border="0" class="table table-hover table-striped" name="raspored" id="raspored" class="tablesorter">
<thead>
<tr COLSPAN=2 BGCOLOR="#6D8FFF">
<th>ИД</th>
<th>Предмет</th>
<th>Професор</th>
<th>Ден</th>
<th>Час</th>
<th>Просторија</th>
<th>Тип</th>
</tr>
</thead>
<?php
foreach ($_POST['predmet'] as $predmet) {
$_SESSION['predmet'] = $_POST['predmet'];
$rows = get_info($db, $predmet);
if (count($rows)){
foreach ($rows as $row) {
$_SESSION['row'] = $rows;
echo "<tr>" .
"<td>" . $row["ID"] . "</td>" .
"<td>" . $row["predmet"] . "</td>" .
"<td>" . $row["profesor"] . "</td>" .
"<td>" . $row["den"] . "</td>" .
"<td>" . $row["chas"] . "</td>" .
"<td>" . $row["prostorija"] . "</td>" .
"<td>" . $row["tip"] . "</td>" .
"</tr>";
}
}
}
?>
</table>
你可以做这样的事情。 缩进不是很正确,但它应该仍然有效。
<?php
session_start(); //call this if you haven't already done so - you'll need to call it before any HTML is output to the page though unless you have output buffering turned on such as via http://php.net/manual/en/outcontrol.configuration.php#ini.output-buffering
if ($_SESSION['table_stored_in_session']) {
echo $_SESSION['table_stored_in_session'];
} else {
ob_start();
?>
<table border="0" class="table table-hover table-striped" name="raspored" id="raspored" class="tablesorter">
<thead>
<tr COLSPAN=2 BGCOLOR="#6D8FFF">
<th>??</th>
<th>???????</th>
<th>????????</th>
<th>???</th>
<th>???</th>
<th>??????????</th>
<th>???</th>
</tr>
</thead>
<?php
foreach ($_POST['predmet'] as $predmet) {
$_SESSION['predmet'] = $_POST['predmet'];
$rows = get_info($db, $predmet);
if (count($rows)){
foreach ($rows as $row) {
$_SESSION['row'] = $rows;
echo "<tr>" .
"<td>" . $row["ID"] . "</td>" .
"<td>" . $row["predmet"] . "</td>" .
"<td>" . $row["profesor"] . "</td>" .
"<td>" . $row["den"] . "</td>" .
"<td>" . $row["chas"] . "</td>" .
"<td>" . $row["prostorija"] . "</td>" .
"<td>" . $row["tip"] . "</td>" .
"</tr>";
}
}
}
?>
</table>
<?php
$table = ob_get_clean();
$_SESSION['table_stored_in_session'] = $table;
echo $table;
}
?>