Hiding default search results

10 posts by 2 authors in: Forums > CMS Builder
Last Post: February 18, 2015   (RSS)

By claire - February 11, 2015

Yeah - on line 245, just before the dealers records loop, add an if-statement to check if the $_REQUEST['maxDistance'] is set. Then only run the loop to display the records if it's there.

Presumably, if it's not there, then no search has been performed and the default record display has to be skipped.

--------------------

Claire Ryan
interactivetools.com

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

Hi, Clare.

Sorry, I don't know how to do this. Line 245 is

<?php foreach ($dealersRecords as $record): ?>

so what should I add, please?

Thanks.

By claire - February 12, 2015

Okay, it should look like this:

<?php if(@$_REQUEST['maxDistance'] != "") : ?>
<?php foreach ($dealersRecords as $record): ?>

.....


<?php endforeach; ?>
<?php endif; ?>

Obviously just add the usual stuff in the foreach loop there.

--------------------

Claire Ryan
interactivetools.com

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

Hi, Clare.

I tried this code, and while it hides the default list of every record, it also doesn't show any results when I run a search. http://mdldoorsystems.com/dealer-interactive.php Any idea where I'm going wrong, please?

<?php if(@$_REQUEST['maxDistance'] != "") : ?>
<?php foreach ($dealersRecords as $record): ?>
<td>

<TABLE WIDTH="100" BORDER="0" CELLPADDING="0" CELLSPACING="0" ID="Product">
<TR>
<TD><P><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?> &raquo; </A><BR>
<?php echo $record['city'] ?>, <?php echo $record['province'] ?>, <?php echo $record['postcode'] ?></P>
<?php if (@$record['_distance']): ?>
<p>Distance: <?php echo round($record['_distance'],1) ?> KM</P>
<?php endif ?>
</TD>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD><IMG SRC="images/single-pixel.gif" WIDTH="369" HEIGHT="1"></TD>
<TD><IMG SRC="images/single-pixel.gif" WIDTH="10" HEIGHT="1"></TD>
</TR>
</TABLE>

</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif ?>

<?php endforeach; ?>
<?php endif; ?>

Attachments:

dealer-interactive.php 16K

By claire - February 13, 2015

Looks like a different variable name - just change this line:

<?php if(@$_REQUEST['maxDistance'] != "") : ?>

to

<?php if(@$_REQUEST['distance'] != "") : ?>

This code checks to see if the distance dropdown has been selected, and it'll only show the results then. But the variable name needs to match what it's called in the dropdown.

--------------------

Claire Ryan
interactivetools.com

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

Aah, thank you!

Hi, Claire.

There's a drop down menu where people can choose the distance from the location they've typed in; i.e. 10, 50 or 100km. Is there a way of excluding any results that exceed the chosen distance? So if they choose, say, 10km, nothing further than that is shown?

Thanks.

Attachments:

dealer.php 14K

By claire - February 18, 2015

Yeah - probably the easiest way is to check the dealer records inside the loop, and add a continue statement if the record's distance is higher than the chosen distance so that it skips those before outputting anything.

--------------------

Claire Ryan
interactivetools.com

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