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
how can i print data into Column with in table
Moderator: General Moderators
-
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
Can you show your php coding for this page?
Something simple like this should work (has done for me in the past)
Replace the Column header with what you want your table headings to be.
Replace the FieldName with your Field names from your Table.
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 tableReplace 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
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>";
?>
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
any body help to try how to divide data.
Re: how can i print data into Column with in table
Try this:
I am taking advantage that </tr> is not a required tag.
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>";
?>-
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
Thanks Budy its working fine .......................