Count fetch results in view file - El Forum - 04-01-2014
[eluser]comyou[/eluser]
Hello everyone,
I currently have a page which displays all Teams and Team Members from MySQL results.
Im trying to make it so that it doesn't show a particular team if there are no members in that team.
The code I have at the moment is:
Code: <div id="content-wrapper">
<div id="content">
<h1>Dynasty Roster</h1>
<?php foreach(fetch('team_mdl') as $team) : ?>
<div class='widget team'>
<h ><span ><?= str_replace('_', ' ', $team->platform) ?></span><?= $team->name; ?></h2>
<ul>
<?php foreach(fetch('team_member_mdl', 'team='.$team->id.'') as $member) : ?>
<li>
<?= $member->firstname ?>"
<?= $member->gamertag ?>"
<?= $member->lastname ?>-
<?= $team->name; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
</div>
I imagine I'd need to do something like
Code: <div id="content-wrapper">
<div id="content">
<h1>Dynasty Roster</h1>
<?php foreach(fetch('team_mdl') as $team) : ?>
<div class='widget team'>
<h ><span ><?= str_replace('_', ' ', $team->platform) ?></span><?= $team->name; ?></h2>
<ul>
<?php foreach(fetch('team_member_mdl', 'team='.$team->id.'') as $member) : ?>
<?php if(///////FETCH_RESULTS /////////!= 0): ?>
<li>
<?= $member->firstname ?>"
<?= $member->gamertag ?>"
<?= $member->lastname ?>-
<?= $team->name; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
</div>
but Im not sure how to go about doing it? :S
Count fetch results in view file - El Forum - 04-01-2014
[eluser]comyou[/eluser]
I've just added a little counter to check, is there a more efficient way?
Code: <div id="content-wrapper">
<div id="content">
<h1>Dynasty Roster</h1>
</div>
<div id="content" 0 !important; margin-top: -20px;">
<?php foreach(fetch('team_mdl') as $team) : $i = 0;?>
<?php foreach(fetch('team_member_mdl', 'team='.$team->id.'') as $member) :
$i += 1;
endforeach;
if ($i > 0):
?>
<div class='widget team'>
<h ><span ><?= str_replace('_', ' ', $team->platform) ?></span><?= $team->name; ?></h2>
<ul class="team-members">
<?php foreach(fetch('team_member_mdl', 'team='.$team->id.'') as $member) : ?>
<li>
<?= $member->firstname ?>"
<?= $member->gamertag ?>"
<?= $member->lastname ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
endif;
?>
<?php endforeach; ?>
</div>
</div>
|