As the subject says, how can I print the mysql result in two or more html columns? Do I have to play around with for-loops and the limit? What have or would you have done?
| SitePoint Sponsor |


As the subject says, how can I print the mysql result in two or more html columns? Do I have to play around with for-loops and the limit? What have or would you have done?
2 columns. No biggee.Code:while ( $row = mysql_fetch_array($result) ) { print("<tr> <td>$row[author]</td> <td>$row[title]</td> </tr>"); }
Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums





Following on to this post, what if you have only one field:
"category"
which had to be in too columns??


thanx aspen, but this is what I already knowwhat I wanted to do is split the result into columns and then print them. So it may look like the php/cgi category's page of HotScripts. Any idea?
Hmm what I showed was the results split in 2 columns.. Maybe you need to explain in more detail exactly what it is you want. I looked at hotscripts and don't see what you mean.
Is it that you want two tables of results side by side?
Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums





DIMA
$numcols = 2;
$count = 1;
print '<tr>';
while ($row = mysql_fetch_array($result)) {
if ($count % $numcols = 0) {
print '<td>yourdata</td></tr><tr>';
}
else {
print '<td>yourdata</td>';
}
$count++;
}
print '</tr></table>';
Please don't PM me with questions.
Use the forums, that is what they are here for.


Hmm.. okay, again: I want to print out the result in at least two columns. For example an index from A to Z. In the first column it should print the first half (A-M) and the second has the other half. Just like the categories at Hotscripts (http://www.hotscripts.com/PHP/Scripts_and_Programs/). So it's not a long list of categories but instead split up in two parts.
How can I do that in PHP? I'm thinking of working with LIMIT in the sql-query...





Maybe its you that is being unclear!
$count = 1;
print '<table border="1"><tr><td>';
for ($i=1;$i<19;$i++) {
while ($row = mysql_fetch_array($result)) {
if ($count == 10) {
print '</td><td>yourdata<br>';
}
else {
print 'yourdata<br>';
}
$count++;
}
print '</td></tr></table>';
Please don't PM me with questions.
Use the forums, that is what they are here for.


Hey thanks! That's what I neededSorry, for being not precise...





DIMA is making two columns with two different fields. How would i put two colums with one field? Making sure that data is repeated.
Example
-----------------------
|Bob | Jack |
|Peter | Jill |
|Jane | Henry |
|Mike | Jemima |
-----------------------
?





Use my first post on this subject
Please don't PM me with questions.
Use the forums, that is what they are here for.





Using your first post i get:
http://www.codingclick.com/subcats.php?cid=1





This is my first post see it a little further up from where you tried
DIMA
$numcols = 2;
$count = 1;
print '<table><tr>';
while ($row = mysql_fetch_array($result)) {
if ($count % $numcols = 0) {
print '<td>yourdata</td></tr><tr>';
}
else {
print '<td>yourdata</td>';
}
$count++;
}
print '</tr></table>';
Please don't PM me with questions.
Use the forums, that is what they are here for.





Results here:
http://www.codingclick.com/subcats.php?cid=1





Can we see the code you used to create that? Its a little hard to debug things when only seeing the output to the screen
Please don't PM me with questions.
Use the forums, that is what they are here for.





print "<table border='1'><tr>";
$numcols = 2;
$count = 1;
print "<tr>";
while ($cat = mysql_fetch_array($write)) {
$id = $cat["ID"];
$name = $cat["SubCat"];
$cid = $cat["CID"];
$description = $cat["Description"];
if ($count % $numcols = 0) {
print "<td><p><a href='list.php?cid=$cid&sid=$id'><font size='+1'><b>$name</b></font></a> " .
"<br><font size='1'>$description</font></td></tr><tr>";
}
else {
print "<td><p><a href='list.php?cid=$cid&sid=$id'><font size='+1'><b>$name</b></font></a> " .
"<br><font size='1'>$description</font></td>";
}
$count++;
}
print "</tr></table>";





Try
if ($count % $numcols == 0) {
instead of
if ($count % $numcols = 0) {
Please don't PM me with questions.
Use the forums, that is what they are here for.





That's it.
Thanx allot.
This one is going into the records. Brilliant script.
Bookmarks