"No listings" link code

6 posts by 3 authors in: Forums > CMS Builder
Last Post: November 14, 2008   (RSS)

By wevolutions - November 12, 2008

How can I get this code below to load in a separate page if there is no matching search listing?

<?php elseif (!$featured_carsRecords): ?>
<table width="525" border="0" cellspacing="1" cellpadding="5">
<tr>
<td align="center" valign="top" bgcolor="#FFFFFF"><font size="3" face="arial"><b>Sorry, No listings were found that matched your search query.<br/>
Please try your search again.</b></font><br/>
</td>
</tr>
</table>
<?php endif ?>

Re: [WEVOLUTIONS] "No listings" link code

By Dave - November 12, 2008

What do you mean by separate page? Like a popup? Or in a different frame? Or just that if there is no matches then it shows a completely different page?
Dave Edis - Senior Developer
interactivetools.com

Re: [WEVOLUTIONS] "No listings" link code

By Kenny - November 13, 2008

One way would be to use an if statement and a javascript redirect.

<?php if ($record['content']): ?>

***Insert html code here***

<?php else: ?>

<script>document.location.href='page2.php'</script>

<?php endif ?>



It may or may not be the best option, but right off the top of my head, it would work.


Kenny

Re: [WEVOLUTIONS] "No listings" link code

By Dave - November 14, 2008

Another way is to put the code up at the top before ANY html is output, like this:

<?php
if (!$featured_carsRecords) {
header("Location: http://www.example.com/newurl.html");
exit;
}
?>


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [WEVOLUTIONS] "No listings" link code

By Kenny - November 14, 2008

Definitely go with Dave's solution - I was wondering how to do a PHP redirect in this situation. They are more reliable than a javascript redirect. There are still a few people who don't have javascript enabled, therefore my solution wouldn't work for them. Since PHP is a server side action, it will always work.

As Dave said - make sure it goes before any HTML or it won't work.

Thanks Dave for the code!