Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

(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...

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

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.