filter listing with 2 combined tables

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 13, 2013   (RSS)

By s2smedia - August 12, 2013

I have a list of communities from one table here:

http://questbuilders.com/test/New-Homes/Homes/

if you click on first community:

http://questbuilders.com/test/New-Homes/Homes/community.php?Majestic-Estates-1

I need the list of models shown on this page to show only models with the community=Majestic Estates

right now my code is always listing ALL models:

<?php foreach ($modelsRecords as $record): ?>

<tr style="background-image:url(images/tealtrans.png); color:#148C8C">

<td style="font-weight:normal"><?php echo htmlencode($record['title']) ?></td>

<td><?php echo htmlencode($record['description']) ?></td>
<td><?php echo htmlencode($record['starting_at']) ?></td>
<td> <?php foreach ($record['elevation_floor_plan'] as $index => $upload): ?>
<a href="http://questbuilders.com/admin<?php echo $upload['urlPath'] ?>" target="_blank" style="color:#000">Download PDF</a>

<?php endforeach ?></td>


</tr>
<?php endforeach ?>

Hi, 

How have you got the relationship between the community and models tables set up? If you have used this method:

http://www.interactivetools.com/kb/article.php?Populate-a-list-field-from-another-section-15

and have the num field for the value of the list field, then you should be able to filter based on the value in the URL like this:

  
  $numValue = getLastNumberInUrl('1');

  // load records from '_nlb_subscribers'
  list($modelsRecords , $modelsMetaData) = getRecords(array(
    'tableName'   => 'models ',
    'where'       => "`community` = '$numValue'",
    'loadUploads' => true,
    'allowSearch' => false,
  ));

This is just example code, so you'll have to make a few changes to get it working with your site.

So get getNumValueFromUrl function will retrieve the last number from the URL. Then this cab used to filter on the community field in the getRecords function. 

This should only return items with a community value that matches the num value passed in the URL.

Let me know if you have any questions.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi,

It looks as if you have the wrong type of brackets around your community field, you need to use this type:

    'where'       => "`community` = '$numValue'",

It's the apostrophe that is above the tab button on the left of your keyboard. Also are you storing the num value in your community field? As the example code i gave you assumed that this is what is being stored.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com