You are here:  » searchExternal.php - how to display in a table?

Support Forum



searchExternal.php - how to display in a table?

Submitted by npaitken on Mon, 2009-07-06 16:18 in

Hi David,

I've been playing around with searchresults_external.php trying to get the results to display in a 3 column table, rather than as 1 product per row, as it displays now. Being hopeless at PHP I'm getting into all sorts of knots.

Can you please help? How does this code need to be modified?

searchresults_external.php

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
 //echo "<div class='featuredarea'>";
  print "<div class='featuredarea'>";
foreach($searchresults["products"] as $product): ?>
  <div class="featuredproduct">
<h3><a href='<?php print $product["productHREF"]; ?>' title='<?php print $product["name"]; ?>'><?php print $product["name"]; ?></a></h3>
    <?php if ($product["image_url"]): ?>
    <p><a href='<?php print $product["productHREF"]; ?>' title='<?php print $product["name"]; ?>'><img width='150' height='150' src='<?php print $product["image_url"]; ?>' alt='<?php print $product["name"]; ?>' title='<?php print $product["name"]; ?>' /></a></p>
    <?php endif; ?>
    <?php if ($product["numMerchants"] > 1): ?>
    <p><em><?php print ("from"); ?></em>&nbsp;<?php print $config_currencyHTML.$product["minPrice"]; ?><br />
    <?php else: ?>
    <p><?php print $config_currencyHTML.$product["price"]; ?><br />
<?php endif; ?>
    <a href='<?php print $product["productHREF"]; ?>' title='<?php print ("Compare Prices"); ?>'><?php print ("Compare Prices"); ?></a>
  </p></div>
<?php endforeach; ?>
</div> <div class="clear"></div>
<?php
  if (file_exists("html/user_searchresults_after.php")) require("html/user_searchresults_after.php");
?>

Submitted by support on Tue, 2009-07-07 08:08

Hi Neil,

Click here for a version of html/searchresults.php (rename as required) that displays results in columns (you can change the number of columns on line 4)...

Cheers,
David.

Submitted by npaitken on Tue, 2009-07-07 10:23

Thanks David,

I've just downloaded and it works great.

Just one small bug though. I've noticed that when I use it with searchExternal.php it adds a paragraph above the search results for every 1 product in the search result. Hence, if there's 5 products returned you get 5 spaces preceeding the search results.

In some posts I have around 20 results and it leaves a huge white space gap!

Any ideas on how to eliminate this?

Thanks,
Neil

Submitted by support on Tue, 2009-07-07 12:04

Hi Neil,

I've come across this before when including HTML with comments into a WordPress page - the comments get wrapped in <p> tags!

To fix this, edit the file and remove the HTML comments from lines 22 and 52...

Cheers,
David.

Submitted by npaitken on Tue, 2009-07-07 12:57

Perfect.

Thanks David