Page 1 of 1

Side by Side Comparison

Posted: Sat May 09, 2009 5:26 am
by petrosa
So, i am building a website where someone can search about houses for rent, and display results based on different criteria, and then display 10 of them in each page, with forward/preivious links.

I want to give the ability to select some of the results and then compare the selected ones side by side, just like comparing similar products found at eshops. The results are fetched from a mysql database. I 'think' i know how to partialy do this, but i am having problems figuring out how to do it, if someone picks some from first page and others from other pages. I could always make it show all the results on a single page, but it would be such a long list.

Any pointers on what would be a good way achieving that?

Thanks in advance

Re: Side by Side Comparison

Posted: Sat May 09, 2009 12:20 pm
by Yossarian
This is something that you would need to use sessions for.

Each time the page returns to the server with a checkbox next to a property you store the ID

Code: Select all

 
<?php
foreach( $chosen as $k=>$v ){
 
$_SESSION['chosen'][] = (int)$v ; // only numbers now
 
}
// uncomment to see what is going on
//var_dump( $_SESSION);
?>
 
When the user finally decides, "compare all my selections" you do a select from the database something like this;

Code: Select all

 
"select title
, price
, bedrooms 
from properties 
where ID in (" .  implode( ',' ,  $_SESSION['chosen'] ) . ")" ORDER BY price " ;
 
 
 
Going through result sets by 10s etc is termed paging or pagination that should get you some tuts.