how can i print data into Column with in table

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
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

how can i print data into Column with in table

Post 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
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

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

Post 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.
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

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

Post 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>";

?>
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

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

Post by manojsemwal1 »

any body help to try how to divide data.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

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

Post 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.
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

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

Post by manojsemwal1 »

Thanks Budy its working fine .......................
Post Reply