Tablejoins -Thought this would be easy

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

By thenetgirl - April 13, 2010

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

By thenetgirl - April 14, 2010

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: [Jason] Tablejoins -Thought this would be easy

By thenetgirl - April 14, 2010

HAPPY DANCE THANKS

Ok now I have a really easy ? so when it has A review at the bottom of the page I want it to say "PROPERTY REVIEWS" and when it doesn't say nothing ..........not sure where & how to put the if on this and right now it is duplicating it for every review.

http://www.pacificgroverentals.com/VacationRentalsDetail.php?125-16-5

<div align="center">
<table border="0" width="90%" id="table23">

<tr>
<td> <?php foreach ($reviewsRecords as $record): ?>
PROPERTY REVIEWS

<p align="left"> <font face="Verdana" size="2" color="#2A4480">
<b> <?php echo $record['property_code'] ?>-<?php echo $record['title'] ?></b></font><br>
<?php echo $record['content'] ?>
<font face="Verdana" size="2" color="#2A4480">
<b> <?php echo $record['reviewers_name'] ?>-<?php echo date("D, M jS, Y", strtotime($record['date'])) ?></b></font></font></td>
<hr color="#0E8A8A" width="99%">
<?php endforeach ?> </tr>
</table>
</div>
Patricia

www.thenetgirl.com

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

By thenetgirl - April 15, 2010

PERFECT YAH THANKS!
Patricia

www.thenetgirl.com