First Attempt advice req'd

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
Unicorn13
Forum Newbie
Posts: 1
Joined: Thu Mar 13, 2008 4:56 pm

First Attempt advice req'd

Post by Unicorn13 »

Hi all,

Newbie here, advice and assistance if you would be so kind.

Ok I am trying to display a products information in a 3 column results style Paginated, each colum 1 record and each record has 5 fields and is displayed as 4 rows in a table with the 4th row split into two columns (subtable).

The information will be kept in flatfile csv, and will nedd to be read into the above, so far I have this,

http://www.ocpdirect.co.uk/bike1/productsgrid.php

Using the following Code:- The problem is I have had to start the counters for the loops at 1, as if I start at 0 as normal it does not display as expected.

Code: Select all

<?php
   echo "<table width='575px' align='center' border='0' cellspacing='0' cellpadding='0'>";
   echo "<tr>";
   for($count=1; $count<=10; $count=$count+1)
   {
   if($count % 3 == 0)
   {
   echo "<td align='center' style='background-color:cyan'>";
   echo "<table width='100%' align='center' border='0' cellspacing='0' cellpadding='0'>";
   echo "<tr>";
   echo "<th style='background-color: yellow;' align='center'>";
   echo "Record: " . $count . " field[0]";
   echo "</th>";
   echo "</tr>";
 
 for($c=1; $c<=3; $c=$c+1)
   {
   if($c == 3)
   {
   echo "<tr>";
   echo "<td style='background-color: #FFD9D9;' align='center'>";
   echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
   echo "<tr>";
   echo "<td width='50%' align='center'>";
   echo "R-" . $count;
   echo ", F-" . $c;
   echo "</td>";
   echo "<td width='50%' align='center'>";
   echo "R-" . $count;
   echo ", F-";
   echo $c+1;
   echo "</td>";
   echo "</tr>";
   echo "</table>";
   echo "</td>";
   echo "</tr>";
   }
   else
   {
   echo "<tr>";
   echo "<td style='background-color: #DFFFFF;' align='center'>";
   echo "R-" . $count;
   echo ", F-" . $c;
   echo "</td>";
   echo "</tr>";
   }
   }
   echo "</table>";
   echo "</td></tr><tr>";
   }
   else
   {
   echo "<td align='center' style='background-color:cyan'>";
   echo "<table width='100%' align='center' border='0' cellspacing='0' cellpadding='0'>";
   echo "<tr>";
   echo "<th style='background-color: yellow;' align='center'>";
   echo "Record: " . $count . " field[0]";
   echo "</th>";
   echo "</tr>";
 
 for($c=1; $c<=3; $c=$c+1)
   {
   if($c == 3)
   {
   echo "<tr>";
   echo "<td style='background-color: #FFD9D9;' align='center'>";
   echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
   echo "<tr>";
   echo "<td width='50%' align='center'>";
   echo "R-" . $count;
   echo ", F-" . $c;
   echo "</td>";
   echo "<td width='50%' align='center'>";
   echo "R-" . $count;
   echo ", F-";
   echo $c+1;
   echo "</td>";
   echo "</tr>";
   echo "</table>";
   echo "</td>";
   echo "</tr>";
   }
   else
   {
   echo "<tr>";
   echo "<td style='background-color: #DFFFFF;' align='center'>";
   echo "R-" . $count;
   echo ", F-" . $c;
   echo "</td>";
   echo "</tr>";
   }
   }
   echo "</table>";
   echo "</td>";
   }
   }
   echo "</table>";
   ?>
The parts that I have not worked :? out yet are Pagination control and how/best way to retrieve this data from the cvs, If anyone can point me in the right direction?

Mnay thanks, and kind regards
Andy
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: First Attempt advice req'd

Post by Christopher »

You should really look into using a template library (Template lite gets mentioned frequently). There is some pagination code in this forum -- search for "pagination".
(#10850)
Post Reply