03-06-2008, 09:20 PM
|
#11 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 87
Thanks: 49
|
Well... it kind of works
I'm using this code:
PHP Code:
<?php
$category_rock = 'SELECT cd_artist FROM products WHERE cd_category = "rock"';
$rock_result = mysql_query($category_rock);
$items = mysql_fetch_array($rock_result);
function array_chunk_vertical($input, $size, $preserve_keys = false, $size_is_horizontal = true)
{
$chunks = array();
if ($size_is_horizontal) {
$chunk_count = ceil(count($input) / $size);
} else {
$chunk_count = $size;
}
for ($chunk_index = 0; $chunk_index < $chunk_count; $chunk_index++) {
$chunks[] = array();
}
$chunk_index = 0;
foreach ($input as $key => $value)
{
if ($preserve_keys) {
$chunks[$chunk_index][$key] = $value;
} else {
$chunks[$chunk_index][] = $value;
}
if (++$chunk_index == $chunk_count) {
$chunk_index = 0;
}
}
return $chunks;
}
$rows = array_chunk_vertical($items, 4);
print "<table border=\"1\">\n";
foreach ($rows as $row) {
print "<tr>\n";
foreach ($row as $value) {
print "<td>" . $value . "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
?>
And it's giving me this result:
But my table looks like this:
It seems to be returning only the first artist with the category "rock", and it's showing it twice for some reason.
|
|
|
|