display data in 4 columns in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vinpkl
Forum Newbie
Posts: 9
Joined: Tue Aug 12, 2008 5:34 am

display data in 4 columns in php

Post by vinpkl »

hi all
i m using this script to fetch and display products in my page.
the "for loop" creates four columns. and the other part fetches and display the products.
but my problem is that i m not able to insert the products into those 4 columns created by "for loop". when i change ($i=result1) then the script doesnt work.

vineet

Code: Select all

 
for($i=1;$i<=1;$i++)
{
   //echo "<tr>";
   echo "<td width=148>" .$i."</td>";
   echo "<td width=148>" .$i."</td>";   
   echo "<td width=148>" .$i."</td>";
   echo "<td width=148>" .$i."</td>";
   //echo "</tr>";         
 
$qry1="select * from product_table";   
$result1 = mysql_query($qry1);           
   if(mysql_num_rows($result1)>0)
   {
   while($row1=mysql_fetch_array($result1))
   {
   
      echo "<table border=1 bgcolor=#ffddee>";
      echo "<tr>";
      echo "<td width=125>" . "<img width=116 height=117 src='admin/uploads/" . $row1['image'] . "'/>" . "</td>";
      echo "</tr>";
      echo "<tr>";
      echo "<td valign=top  width=125>". $row1['product_name'] . "</td>";
      echo "</tr>";
      echo "<tr>";
      echo "<td valign=top>". $row1['description'] . "</td>";
      echo "</tr>";
      echo "<tr>";
      echo "<td valign=top class=cut>". $row1['cutout_price'] . "</td>";
      echo "</tr>";
      echo "<tr>";
      echo "<td valign=top>". $row1['price'] . "</td>";
      echo "</tr>";
      echo "</table>";
   }
   
   }
   
}
 
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: display data in 4 columns in php

Post by requinix »

It's early morning and I don't feel like sorting through that mess, so

Code: Select all

 
begin table;
 
$column = 1; some sort of loop here {
    if ($column == 1) begin new row;
    print table cell here;
    if ($column++ == 4) {
        end row;
        $column = 1;
    }
}
 
end table;
Prints stuff left-to-right, top-to-bottom.
Post Reply