Now I have a little project that is scheduled to be released tommorow. What I need to do is display albums. Now the icons I have for the albums are small so I could probably fit 4 total album results in a row then have to start another whole row of albums.
By total album result I mean this:
[CODE]
| name | name | name | name |
| desc | desc | desc | desc |
| date | date | date | date |
then next row:
| name | name | name | name |
| img | img | img | img |
| date | date | date | date |
8 is the maximum albums I will allow.
Now I know I will have to use some sort of counter and I have heard for each loops are the best for arrays, so let me take a little stab at it.
[code=php]// Albums //
function albums()
{
global $image_block;
$album_table = “albums”;
$album_sql = ”
SELECT `id`,
`album_name`,
`album_desc`,
DATE_FORMAT(`date_created`,’%M-%d-%Y’) `date_created`
FROM $album_table
ORDER BY `date_created` DESC”;
$album_result = mysql_query($album_sql) or die (‘Error line 36:’ . mysql_error());
/////////////////////////////////////////////
//here is the part I can’t do yet
$count = 0
echo “<table>
<tr>”;
foreach( $album_result[‘name’] as $name )
{
echo ‘ <td>’.$name.”</td>n”;
$count++
}
echo “</tr><tr>”;
foreach( $album_result[‘desc’] as $desc )
{
echo ‘ <td>’.$desc.”</td>n”;
}
echo “</tr><tr>”;
foreach( $album_result[‘date_created’] as $date )
{
echo ‘ <td>’.$date.”</td>n”;
}
echo ” </tr>
</table>”;
////////////////////////////////
The problem is with even this lame example it is wrong, and I can’t control how many total results will display. How do I access the elements in the array “$album_result” and then limit it so there is only 4 total columns in the first “row” and continue on where it left off to finish it up?
Please help. Arrays are difficult for me and foreach loops in php I barely know the syntax.