Hi,
I think you can solve both of these problems using the array_groupBy function. To list the logo of each home and away team I would retrieve all of the teams in a seperate variable, and then sort them by their num value using array_groupBy. Then you can easily find each teams details, something like this would work:
<?php
// load records from 'members'
list($teams, $teamsMetaData) = getRecords(array(
'tableName' => 'teams',
'loadUploads' => true,
'allowSearch' => false,
));
//Sort the teams by there num value
$teams = array_groupBy($teams, 'num', false);
// load records from 'members'
list($matches, $matchesMetaData) = getRecords(array(
'tableName' => 'matches',
'loadUploads' => true,
'allowSearch' => false,
));
//Sort and group the matches by the round number
$matches = array_groupBy($matches, 'round_num', true);
?>
then you'd use the following code to display the entries on the page:
<h1>Matches</h1>
<!-- matches have been grouped by round, so cycle through the rounds -->
<?php foreach($matches as $round): ?>
<ul>
<!-- cycle through the matches in each round -->
<?php foreach($round as $match): ?>
<li>
Result: <?php echo $match['result']; ?><br>
<!-- display the match home teams title, teams have been sorted by num, so we can use the num value to find the team in the array -->
Home team: <?php echo $teams[$match['team_home']]['title']; ?><br>
Away team: <?php echo $teams[$match['team_away']]['title']; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
This is just example code, so you'll probably need to make changes to get it working.
So the array_groupBy function requires the array you want to sort, the field you want to sort by, and a Boolean for if you want to group by the field or not. So I've sorted the teams by their num value, then you can use the team num value to find the correct home and away team in the array.
I've used the array_groupBy function on the matches as well, but grouped them by the round_num, this will create an array where all of the items with the same round_num will be grouped together, then you can cycle through each item.
I'd recommend using the showme function on matches and team variables so you can see the structure the array_groubBy function creates:
showme($matches);
echo "<hr>";
showme($teams);
Let me know if you have any questions.
Thanks!
Greg
Greg Thomas
PHP Programmer - interactivetools.com