2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 20, 2014   (RSS)

By kovali - February 14, 2014


I'm building a website with real estate projects (category: PROJECTS), where each project consists of many different buildings (category: BUILDINGS). In projectsDetail.php I want to show the detailed information of a project together with all the corresponding buildings (and their records) within that project. To link a building to a project I'm using a dropdown select list as a record that is populated with the project titles. My question: Is it possible to show all the records of these 2 categories on one page ?? What would be the best solution to deal with this type of situation please ?

Thanks in advance,


By Daryl - February 20, 2014

Hi Koen,

If I understand it correctly, you want to show one project and all the buildings (and their records) under that project in projectDetail.php, is that right?

What I'd usually do in this kind of cases is to, first, load the project records. Example:

  // load record from 'projects'
  list($projectsRecords, $projectsMetaData) = getRecords(array(
    'tableName'   => 'projects',
    'where'       => "`num` = '".mysql_escape(@$_REQUEST['projectRecordNum'])."'", // @$_REQUEST['projectRecordNum'] is the project record num that you want to load
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  $projectsRecord = @$projectsRecords[0]; // get first record
  if (!$projectsRecord) { dieWith404("Record not found!"); } // show error message if no record found

And then load all the buildings that are linked to that project. In your case is via dropdown list field, for example, let's call that field "parent_project":

  // load records from 'buildings'
  list($buildingsRecords, $buildingsMetaData) = getRecords(array(
    'tableName'   => 'buildings',
    'loadUploads' => true,
    'allowSearch' => false,
    'where'       => 'parent_project = "'.mysql_escape($projectsRecord['num']).'"',

Now that I have all the data, I can now display them in the page. Since the $buildingsRecords might have multiple records, I will display them by looping through each. Example:

// display the project records
echo htmlspecialchars($projectsRecord['name']);
echo htmlspecialchars($projectsRecord['date']);
//.. and so on

// display all the buildings under this project
if ($buildingsRecords){
  foreach ($buildingsRecords as $building){
    echo htmlspecialchars($building['name']);
    echo htmlspecialchars($building['number']);
    //.. and so on

Hope this helps!

Daryl Maximo
PHP Programmer - interactivetools.com