Forum Moderators: coopster
<?php
$result = mysql_query("
SELECT
A.ID,
A.style,
A.tn,
A.desc
FROM
A
WHERE
A.ID >0");
if($r = mysql_fetch_array($result))
{
print("<table>");
print("<tr>");
$num = @mysql_num_rows($result);
$thumbcols = 3;
$thumbrows = 1+ round($num / $thumbcols);
function display_table() {
global $num, $result, $thumbrows, $thumbcols;
for($r=1;$r<=$thumbrows;$r++) {
print '<tr>';
for($c=1;$c<=$thumbcols;$c++) {
print '<td bgcolor="#999999" align="center" valign="top">';
printf("<a href=\"%s?ids=%s\"><img src=http://foobar.com/foobar/styles/%s></a><br>\n", $PHP_SELF, $r["ID"], $r["tn"]);
printf("<a href=\"%s?ids=%s\">%s</a><br>\n", $PHP_SELF, $r["ID"], $r["style"]);
print("</td>");
}
print("</tr>");
}
}
display_table();
print("</table>");
}
else {
print ' ';
}
?>
Any suggestions. I feel like I am close, but OH SO FAR!
Is it ethical to use the tutorial script in this way?
Thanks
[edited by: ergophobe at 4:10 pm (utc) on Oct. 9, 2004]
[edit reason] fixed sidescroll [/edit]
This snippet of code was posted by coopster a while back:
$item_per_row = 3;
$content = '<tr>';
$sql = "SELECT * FROM table";
$rows = mysql_query($sql);if (mysql_num_rows($rows) == 0)
{
$content = '<td>No Items</td></tr>';
}
else
{
$count = 0;
while ($row = mysql_fetch_assoc($rows))
{
$content .= '<td>' . $row['item'] . '</td>';
if (++$count % $item_per_row === 0)
{
$content .= '</tr>';
}
if ($count % $item_per_row!== 0)
{
$content .= '</tr>';
}
It works like a charm and may be some use to you.
:)
<table border=5>
<?
$item_per_row = 3;
$content = '<tr>';
$sql = "SELECT name FROM table";
$rows = mysql_query($sql);
if (mysql_num_rows($rows) == 0) {
$content = '<td>No Items</td></tr>';
} else {
$count = 0;
while ($row = mysql_fetch_assoc($rows)) {
$content .= '<td>' . $row['name'] .'</td>';
if (++$count % $item_per_row === 0) {
print $content .= '</tr>';
}
}
if ($count % $item_per_row!== 0) {
$content .= '</td>';
}
}
?>
</table>
[edited by: jatar_k at 10:40 pm (utc) on Oct. 8, 2004]
[edit reason] reformatted code [/edit]
<table border=5>
<?
$item_per_row = 3;
$content = '<tr>';
$sql =
"SELECT
a,
b,
c,
d
FROM
table
GROUP BY
d
ORDER BY
d
ASC
";$rows = mysql_query($sql);
if (mysql_num_rows($rows) == 0)
{
$content = '<td>No Items</td></tr>';
}
else
{
$count = 0;
while ($row = mysql_fetch_assoc($rows))
{
$s='http://foo.com';
$content .= '<td valign=top>' . '<b><a href=http://foo.com/bar.php?idg='.$row['a'].'>'.$row['b'] .'</a></b><br>' . $row['c'].'<br>' .'<img src=http://foo.com/bar/'.$row['d'] .'>'. '</td>';
if (++$count % $item_per_row === 0)
{
}
}
print $content .= '</tr>';
}
if ($count % $item_per_row!== 0)
{
$content .= '</td>';
}
?>
</table>
This prints one row, with the mysql rows arranged in columns.
Getting there.......
ideas?