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)

By fleff - August 2, 2010

Why does this code work on the properties_details.php page but not on the properties.php page? It's near the top of the page above the foreach section.

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

I get this message:

Notice: Undefined variable: propertiesRecord in /usr/home/klemmr/www/htdocs/properties.php on line 138 in Notice: Undefined variable: propertiesRecord in /usr/home/klemmr/www/htdocs/properties.php on line 138 , Notice: Undefined variable: propertiesRecord in /usr/home/klemmr/www/htdocs/properties.php on line 138

The viewer library on the properties.php page is:

// load records
list($propertiesRecords, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'orderBy' => 'price+0 DESC',
'perPage' => '48',
));

The rest of the page works fine in producing the list of properties. What do I need to do to make this work? I didn't find anything in the forum to help me.

Thanks,

Farnham

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: [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