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