我需要一些关于我永恒之谜最后一块的帮助:P
我有这段代码:
<?php
require_once 'connection.php';
require 'vendor/autoload.php';
$skoleListe = Skole::all();
$arrangementsListe = Arrangement::all();
$skoleAttributter = '';
$arrangementsAttributter = '';
$skoleIsSet = '';
if(isset($_GET['skoleId']))
{
$skoleIsSet = $_GET['skoleId'];
}
else {
echo 'Velg skole!';
}
foreach($skoleListe as $skole)
{
$skoleAttributter.= '<option value="index.php?skoleId=' . $skole['id'] .
'">' . $skole['navn'] . '</option>';
}
foreach($arrangementsListe as $arrangement)
{
$arrangementsAttributter.= '<option value="index.php?skoleId=' . $skoleIsSet
. "&arrangement=" . $arrangement['type'] . '">' . $arrangement['type'] .
'</option>';
}
?>
<select onchange="this.options[this.selectedIndex].value && (window.location= this.options[this.selectedIndex].value);">
<option value="">Velg campus</option>
<?= $skoleAttributter; ?>
</select>
<select onchange="this.options[this.selectedIndex].value && (window.location= this.options[this.selectedIndex].value);">
<option value="">Velg arrangementstype</option>
<?= $arrangementsAttributter; ?>
</select>
<?php
$Arrangementer = Arrangement::with('skoler')->get();
$skoleId = '';
$arrangementIsSet = isset($_GET['arrangement']);
$skoleIsSet = isset($_GET['skoleId']);
if(isset($_GET['skoleId'])) {
$skoleId = $_GET['skoleId'];
foreach ($Arrangementer as $arrangement) {
if ($arrangement['skole_id'] == $skoleId) {
include 'card.php';
}
}
}
我的card.php看起来像这样:
<h2><?= $arrangement['overskrift'] ?></h2>
<p>Sted: <?= $arrangement['sted'] ?></p>
这个想法是根据学校排列安排。 我没试过各种if / else语句。
我有什么想法可以做到这一点?关于如何使我的代码更有效的任何一般性建议?顺便说一下,我正在使用Eloquent库。