Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
getRelatedRecords.example.php
Go to the documentation of this file.
1 <?php
2 require_once 'dataface-public-api.php';
3 
4 // load student record with last name 'Hannah'
5 $student =& df_get_record('Students', array('LastName'=>'Hannah'));
6 
7 // The $student variable now contains a Dataface_Record object.
8 
9 // Get the first 30 courses that this student has enrolled in -- assumes that the 'Courses' relationship is defined appropriately in relationships.ini file.
10 $courses =& $student->getRelatedRecords('Courses')
11 
12 // $courses now contains an array of associative arrays with Course information.
13 
14 // Iterate through the courses and print them in a table.
15 echo '<table>
16  <thead>
17  <tr>
18  <th>Course ID</th>
19  <th>Course Name</th>
20  <th>Course Description</th>
21  </tr>
22  </thead>
23  <tbody>
24  ';
25 foreach ( array_keys($courses) as $index){
26  echo '
27  <tr>
28  <td>'.$courses[$index]['CourseID'].'</td>
29  <td>'.$courses[$index]['CourseName'].'</td>
30  <td>'.$courses[$index]['CourseDescription'].'</td>
31  </tr>
32  ';
33 }
34 echo '</tbody>
35  </table>
36  ';
37 ?>