I need some help with this one. I would like the results of this script shown in table format, or with multiple columns. This script basically takes the results of a web form and search's my linkshare affiliates for any products matching the search criteria. Whatever is found is displayed in a single column the width of the entire page. I would like multiple items per row, maybe 3. How would I get this to work here? I have looked all over the place and have found some things but cant figure out how to incorporate it into this particular script. Any help is greatly appreciated.

<?
  //$url = "http://feed.linksynergy.com/productsearch";
  $url = "http://65.245.193.50/productsearch";
  $token = "";  // Add your LinkShare token here
 
  $results = '';
  $resturl = $url."?"."token=".$token;
 
  if (isset($_GET["keyword"]))
  {
  	$keyword = $_GET["keyword"];
  	$resturl .= "&keyword=".$keyword;
  }
 
  if (isset($_GET["cat"]))
  {
  	$category = $_GET["cat"];
  	$resturl .= "&cat=".$category;
  }
 
  if (isset($_GET["max"]))
  {
  	$maxresults = $_GET["max"];
  	$resturl .= "&max=".$maxresults;
  }
 
  if (isset($_GET["mid"]))
  {
  	$mid = $_GET["mid"];
  	$resturl .= "&mid=".$mid;
  }
 
  $SafeQuery = urlencode($resturl);
  $xml = simplexml_load_file($SafeQuery);
 
  if ($xml)
  {
    foreach ($xml as $item) {
        $link  = $item->linkurl;
        $title = $item->productname;
        $imgURL = $item->imageurl;
        $price = $item->price;
        $merchantname = $item->merchantname;
        $description = $item->description->short;
 
        if($link != "")
	        $results .="<div id=\"product\">
	        		<div id=\"product_img\"><a href=\"$link\"><img border=\"0\" src=\"$imgURL\"/></a></div>
	        		<div id=\"product_link\"><a href=\"$link\">$title</a></div>
	        		<div id=\"product_price\">Add to Cart: <a href=\"$link\">$price</a></div>
	        		</div>";
	}
  }
 
  if ($results == '') { $results = "<div id=\"product\">There are no available products at this time.</div>"; }
 
  print $results;
?>

The most straightforward way is to use a table:

1. Define the table before the foreach statement (e.g. $results .= "<table width=95%>")

2. You may want to define a header row (e.g. $results .= "<tr><th>xxxx<th>yyyy...)

3. Keep a count of what column you are processing. When you get to column 4 reset it to one and generate a new line (<tr>)

4. For each field you can put a <td> ahead of it to make it a separate column.

You will need to consider the amount of data in each column and if three columns will actually fit across the page. You can use the same approach for just two columns if three is too many.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.