Page 1 of 1

how can i print data into Column with in table

Posted: Mon Dec 14, 2009 5:32 am
by manojsemwal1
hai any body knows how can i divided data into column. i have a row, having courseName its around 80 or 90course
when i fetching the data its showing in long row or long column. i want to break the row after 10 course with in the table like....

a g m
b h n
c i o
d j p
e k q
f l r

all are should be in proper table format...

pl give some nice solutions in php

Re: how can i print data into Column with in table

Posted: Mon Dec 14, 2009 5:41 am
by aravona
Can you show your php coding for this page?

Something simple like this should work (has done for me in the past)

Code: Select all

 
$sql = "select * from [your table]"; //runs a query
 
$result = mysql_query($sql,$conn); //result of the query
 
      echo "<table border='1'>"; //creates a table in html
      echo "<tr><th colspan='10' align='center'>Column Header</th></tr>";
      echo "<tr><th>Column Header</th>
              <th>Column Header</th>
              <th>Column Header</th>
              <th>Column Header</th></tr>";
 
while($row = mysql_fetch_array($result)) { //loops while there are results for the query and displays in table using the echo's below
        echo "<tr><td> $row[FieldName] </td><td> $row[FieldName] </td>";
        echo "<td> $row[FieldName] </td><td> $row[FieldName] </td>";
        echo "<td> $row[FieldName] </tr>";
          }
 
     echo "</table>"; //ends the table
Replace the Column header with what you want your table headings to be.

Replace the FieldName with your Field names from your Table.

Re: how can i print data into Column with in table

Posted: Mon Dec 14, 2009 10:55 pm
by manojsemwal1
Thanks For Your reply

iam having only one column and one column having list of data its having 80 or 90 row. so i wana break the column in short.

<?php

$sql = "select CourseId, CourseAbbr from coursetb";

$rs = mysql_query($sql) or die(mysql_errormsg());
//$count=mysql_num_rows($rs);


$n = 1;
echo"<table border=0 cellspacing=4 cellpadding=2><tr><td>";
while ($row = mysql_fetch_assoc($rs))
{

echo '<input type="checkbox" name="courseid[]" value="'.$row['CourseId'].'" > '. $row['CourseAbbr'] .' ';

if($n%10 == 0)
{
echo '<br />';
}
$n++;
}

echo"</td></tr></table>";

?>

Re: how can i print data into Column with in table

Posted: Mon Dec 28, 2009 4:01 am
by manojsemwal1
any body help to try how to divide data.

Re: how can i print data into Column with in table

Posted: Mon Dec 28, 2009 1:27 pm
by manohoo
Try this:

Code: Select all

<?php
$cellsPerRow = 5; //change this to whatever value you want
 
echo "<table>";
 
for ($i=0 ; $i<100 ; $i++)
if (($i % $cellsPerRow) == 0)
  { echo "<tr> <td> $i </td>";
}
else { echo "<td> $i </td>";
}
  
echo "</table>"; 
?>
I am taking advantage that </tr> is not a required tag.

Re: how can i print data into Column with in table

Posted: Mon Dec 28, 2009 11:47 pm
by manojsemwal1
Thanks Budy its working fine .......................