/    Sign up×
Community /Pin to ProfileBookmark

photo album in a array

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 |

[/CODE]

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>”;

////////////////////////////////
[/code]

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.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@Markbad311authorSep 16.2006 — should there be a for loop and an if statement to catch incomplete columns? say like its 4 columns and I have 5 albums. I will need to get the count using some other loop and an if statement. I am still trying to figure this out. forgive the bump up.
Copy linkTweet thisAlerts:
@ronverdonkSep 16.2006 — You can replace the part 'you can't do' with the following. I have echoed all data of each row in one <td> using breaks to get it below each other in the same table cell. I have not tested this.
[code=php]
$count = 0;
echo "<table>";
while ($row = mysql_fetch_assoc($album_result)) {
if ($count == 0)
echo "<tr>";
echo '<td>'.$row['name']."<br>".$row['desc']."<br>".$row['date']."</td>";
if ($count++ > 4) {
echo "</tr>";
$count = 0;
}
}
echo "</table>"
[/code]


Ronald ?
Copy linkTweet thisAlerts:
@bokehSep 16.2006 — If you were to use an unordered list [I]<ul>[/I] there would not be a need to count anything. The list would create as many columns as the page allowed and would reduce the number of columns depending on screen resolution and level of maximization. [URL=http://bugster.co.uk/thumbs]Example one[/URL]! [URL=http://www.revista-foto.es/foto-del-dia.php]Example two[/URL]!
Copy linkTweet thisAlerts:
@Markbad311authorSep 16.2006 — Thank you ronverdonk that helped a lot. Bokeh great trick. I never thought about a list with a little css. That makes perfect sense and saves a lot of work for me. I appreciate the help and I will let you know how it turns out.
Copy linkTweet thisAlerts:
@bokehSep 17.2006 — Pity about the tables everywhere else!
Copy linkTweet thisAlerts:
@Markbad311authorSep 23.2006 — explain please....
×

Success!

Help @Markbad311 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...