Page 1 of 1

display data in 4 columns in php

Posted: Tue Oct 21, 2008 4:06 am
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>";
   }
   
   }
   
}
 
 

Re: display data in 4 columns in php

Posted: Tue Oct 21, 2008 4:27 am
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.