Tablejoins -Thought this would be easy

7 posts by 2 authors in: Forums > CMS Builder
Last Post: April 15, 2010   (RSS)

I have a real estate site they want to add reviews - An because there can be many reviews for one property -I decided the most common thing was the property code. So I set up a new table to add reviews I bacically want to say if this property code matches that property code post this info.

this is myheader

<?php
require_once "/home/mtyrents/www/pacificgroverentals.com/cmsAdmin/lib/viewer_functions.php";
require_once "init.php";

list($vacation_rentalsRecords, $vacation_rentalsMetaData) = getRecords(array(
'tableName' => 'vacation_rentals',
'joinTable' => 'homepages',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$vacation_rentalsRecord = @$vacation_rentalsRecords[0]; // get first record

// show error message if no matching record is found
if (!$vacation_rentalsRecord) {
print "Record not found!";
exit;
}

list($reviewsRecords, $reviewsMetaData) = getRecords(array(
'tableName' => 'reviews',
));
?>

I want to say <php? if $vacation_rentalsRecord['property_code'] = $reviewsRecords['property_code']: ?> PRINT REVIEWS but it doesnt seem to be correct.



thanks for your help

PG
Patricia

www.thenetgirl.com

Re: [thenetgirl] Tablejoins -Thought this would be easy

By Jason - April 14, 2010

Hi,

You're very close. All we need to do with change how we get our "reviews" records. Right now we're getting all of the review records, but since we're only returning 1 vacation_rentalsRecords we only want to get the reviews associated with this property.

We need to change the code to this:
list($reviewsRecords, $reviewsMetaData) = getRecords(array(
'tableName' => 'reviews',
'where' => 'property_code='.$vacation_rentalsRecord['property_code'],
));


$reviewsRecords will now be a list of all of the reviews associated with our property_code. You can now output them using the following:

<?php foreach ($reviewRecords as $review) : ?>
*OUTPUT REVIEWS*
<?php endforeach ?>


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/

Re: [Jason] Tablejoins -Thought this would be easy

Nothing outputted -

<?php
require_once "/home/mtyrents/www/pacificgroverentals.com/cmsAdmin/lib/viewer_functions.php";
require_once "init.php";

list($vacation_rentalsRecords, $vacation_rentalsMetaData) = getRecords(array(
'tableName' => 'vacation_rentals',
'joinTable' => 'homepages',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$vacation_rentalsRecord = @$vacation_rentalsRecords[0]; // get first record

// show error message if no matching record is found
if (!$vacation_rentalsRecord) {
print "Record not found!";
exit;
}


list($reviewsRecords, $reviewsMetaData) = getRecords(array(
'tableName' => 'reviews',
'where' => 'property_code='.$vacation_rentalsRecord['property_code'],
));
?>



I attached my page ...........the review is at the bottom before - [font "Verdana"] No record found!
Patricia

www.thenetgirl.com

Re: [thenetgirl] Tablejoins -Thought this would be easy

By Jason - April 14, 2010

Hi,

Let's try this. Change "where" line to this:
'where' => 'property_code='."'".$vacation_rentalsRecord['property_code']."'",

Give that a try. If this doesn't work, can you give me an example of what a property code looks like.

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/

Re: [thenetgirl] Tablejoins -Thought this would be easy

By Jason - April 15, 2010

Hi,

Try this code before your foreach loop:

<?php if($reviewsRecords) : ?>
PROPERTY REVIEWS
<?php endif ?>


You can add any HTML formatting you want around it as well.

Hope that 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/

Re: [Jason] Tablejoins -Thought this would be easy

PERFECT YAH THANKS!
Patricia

www.thenetgirl.com