Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5155 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted (edited)

(PHP newbie beware)

I am working with 2 tables, Classes and Sessions.

I have built a page to display a list of Sessions, showing their related class title. I am looking for a way to group the results based on Class title, showing the title and description only once and the available sessions below.

Below is all the PHP code to what I have created so far. If you have any suggestions or can point me to an article that will help, it would be much appreciated.

thanks

grum

<?php

 error_reporting(E_ALL);

 require_once('db.php');





$request = $fm->newFindCommand('php_Session');

$request->addFindCriterion('StartDate', '>= //' );

$request->addSortRule('php_Class::classTitle', 1, FILEMAKER_SORT_ASCEND);

$result = $request->execute();





$records = $result->getRecords();







$html = '

Sessions Available

'; $group = array(); $group['total_class'] = 0; foreach ($records as $record) { $html .= '
'; $html .= ''. $record->getField ('StartDate'). ''; $html .= ''. $record->getField ('php_Class::__kp_Class'). ''; $html .= ''. $record->getField ('php_Class::classTitle'). ''; $html .= ''. $record->getField ('php_Class::classDescription'). ''; } ?>

Edited by Guest
  • 2 weeks later...
Posted (edited)

Your html is technically invalid on the grounds that you're using the same id multiple times but never mind that...

Easiest way is the following (though there are a few other ways you could do it).


$groups = array();

/*Collect records in to groups*/

foreach ($records as $record) {

	$groups[$record->getField('php_Class::classTitle')][] = $record;

}



/*Process Groups*/

foreach($groups as $groupname=>$recordsInGroup){

	$firstRecInGroup = current($recordsInGroup);

	echo "

".$groupname."

"; echo " ".$firstRecInGroup->getField('php_Class::classDescription').""; echo "
"; foreach($recordsInGroup as $record){ echo $record->getField ('StartDate').''; } }

Edited by Guest

This topic is 5155 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.