help with a new details page

2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 18, 2010   (RSS)

Hello guys,

We are redesigning our details pages and are having some trouble with the coding of some new features.

1. We want to add a section on a details page of Other Rental Listings that a user owns. For example, you a viewing a property that Bob has listed on our site (property #1). We want to display in a box, property #2, #3 and #4 (pic and name of property)that Bob owns.

This code pulls 1 of Bob's properties:
<?php require_once "../cmsAdmin/lib/viewer_functions.php";

list($commercial_rental_propertyRecords, $commercial_rental_propertyMetaData) = getRecords(array(
'tableName' => 'commercial_rental_property',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$commercial_rental_propertyRecord = @$commercial_rental_propertyRecords[0]; // get first record


Can we just add another chunk of code on the same page to pull other listings or will we need to make this an include file?
list($commercial_rental_propertyRecords, $commercial_rental_propertyMetaData) = getRecords(array(
'tableName' => 'commercial_rental_property',
'where' => createdByUserNum = (Bob's user num),
));


Finally, the last issue we were having with this was begin able to write the correct code for the WHERE statement. I assume we will have to define a variable $user=$record['createdByUserNum'];
and use this where statement in the code above

'where' => createdByUserNum = $user,
But I was getting undefined index errors when I used "record" and/or "commercial_rental_propertyRecord" when trying to define the variable. I can get the createdByUserNum to display on the page just fine, but trying to pull it into a variable was not working.

2. Similar to the above feature, but a little different.
We want to display related rental listings from all users. So for Bob's Commerical Rental Property we want to display, in a separate box, electronic rentals, office furniture, etc that have a cities_serviced_keyword that matches the city that Bob's property is in. I again believe that this will be a where statement for each of the categories that we choose to display for this section. Such as
where => ' cities_serviced LIKE city',
(Our cities_services field is a text box that lists any cities a company services. Each city is separated by a comma. ) I not too familiar with the LIKE function and not sure if that is the correct/best way to do it.

Your help is greatly appreciated as always.
Thanks!
Jason Glass

Re: [rentittoday] help with a new details page

By Jason - November 18, 2010

Hi,

It looks like you're pretty close on both of these issues.

1) You'll need to change you're query to look like this:



list($commercial_rental_propertyRecordsByUser, ) = getRecords(array(
'tableName' => 'commercial_rental_property',
'where' => "createdByUserNum ='".intval($commercial_rental_propertyRecord['createdByUserNum'])."' AND num!='".intval($commercial_rental_propertyRecord['num'])."'",
));


The second half of the "where" statement is so you don't select the same record twice. It is important that this query appear after your first query. It is also important to always use new variable names (ie $commercial_rental_propertyRecordsByUser) so you don't overwrite other variables by mistake.

2) It's a similar situation here. You'll need to change your variable name and your query like this:

list($commercial_rental_propertyRecordsByCity,) = getRecords(array(
'tableName' => 'commercial_rental_property',
'where' => "cities_serviced LIKE '%".mysql_escape($commercial_rental_propertyRecord['city'])."%' AND num!='".intval($commercial_rental_propertyRecord['num'])."'",
));


Using "%" before and after the city name means will will return records where the city name appears anywhere in the cities_serviced text. Again we added code so that we won't select the same record twice.

Give this a try and let me know if you run into any issues.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/