Code works on Details page but not on List page

4 posts by 3 authors in: Forums > CMS Builder
Last Post: August 3, 2010   (RSS)

Re: [fleff] Code works on Details page but not on List page

By Ryan - August 3, 2010

Your code should be inserted inbetween your foreach statements on the list page. The detail page deals with a specific record were as the list page displays multiple records and therefore needs the foreach statement.

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

<table align="center" bgcolor="#E8DEA4" width="900" border="0" cellspacing="0" cellpadding="10"> <tr> <td align="center" valign="top"> <div class="page_title"><?php echo $propertiesRecord['listing_heading'] ?> in <?php echo $propertiesRecord['property_town'] ?>, <?php echo $propertiesRecord['state'] ?></div> <span class="new_info"><?php echo $propertiesRecord['new_info'] ?></span> </td> </tr> </table>

<?php endforeach ?>



Ryan

Re: [ryan_dot] Code works on Details page but not on List page

By fleff - August 3, 2010

Thanks, Ryan, for your response. I had tried that and I get the same error message repeated on the page by the number of times that I have records for that table.

I think I see where this problem lies. I'm asking it to read the fields of all the records and there are different values in each of them, where I only want one. Actually, I'm working with a field called "status" as a header on the page that says whether the property is For Sale or For Rent. I used the sample above as an example that worked on the details page but now I see why it won't work on the list page. I'll have to approach this from another perspective. Let's see where it goes.

Farnham

Re: [fleff] Code works on Details page but not on List page

By Chris - August 3, 2010 - edited: August 3, 2010

Hi Farnham,

The code you pasted above references a variable called $propertiesRecord:

<div class="page_title"><?php echo $propertiesRecord['listing_heading'] ?> in <?php echo $propertiesRecord['property_town'] ?>, <?php echo $propertiesRecord['state'] ?></div>
<span class="new_info"><?php echo $propertiesRecord['new_info'] ?></span>


But that variable isn't available on the list page. Instead, there's a variable called $propertiesRecords (note the "s"). $propertiesRecords will be a list of records, while $propertiesRecord will be a single record. The code you pasted only works with a single record.

Ryan is right, you can get this code to work on your list page by placing it inside your FOREACH, but you'll also need to change the variable name to match it. Assuming that your FOREACH starts like this:

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

...you'll need to change your code to reference the $record variable (changing $propertiesRecord to $record):

<table align="center" bgcolor="#E8DEA4" width="900" border="0" cellspacing="0" cellpadding="10">
<tr>
<td align="center" valign="top">
<div class="page_title"><?php echo $record['listing_heading'] ?> in <?php echo $record['property_town'] ?>, <?php echo $record['state'] ?></div>
<span class="new_info"><?php echo $record['new_info'] ?></span>
</td>
</tr>
</table>


Does that help? Please let me know if you have any questions.
All the best,
Chris