/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with displaying query results

I have a photo gallery and I need help displaying the query results – thumbnail pictures.

Right now when someone selects an album category the thumbnail pictures are displayed down the page one on top of the other. This is rather simple as it’s just:

[CODE]<tr><td><a href=’./bigimage/pic1.jpg’>pic1_th.jpg</a></td></tr>[/CODE]

It produces a new table row for each thumbnail until it reaches the limit set in the query.

Instead, I’d like to have four thumbnails per row and have it make as many rows as necessary to meet the limit per page set in the query. If you’re familiar with Coppermine, it would be like how they have their thumbnails displayed.

I’m not sure how to go about writing the code to do this.

[CODE]$sql = “SELECT * FROM $tbl_name WHERE cat_id=’$cat_id’ ORDER BY id LIMIT $start, $limit”;
$result = mysql_query($sql);

while($row = mysql_fetch_array($result)) {
$id = $row[‘id’];
$cat_id = $row[‘cat_id’];
$imagename = stripslashes($row[‘imagename’]);
echo ”
<tr>
<td><‘./bigpic/$imagename’>$imagename</a></td>
<td><‘./bigpic/$imagename’>$imagename</a></td>
<td><‘./bigpic/$imagename’>$imagename</a></td>
<td><‘./bigpic/$imagename’>$imagename</a></td>
</tr>
“;
}[/CODE]

How do I get it to automatically make a new cell (up to four) and a new row if necessary?

Thanks.
Alan P

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Alan_PauthorDec 07.2010 — I found that I could achieve what I wanted by using nested loops.
×

Success!

Help @Alan_P 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.25,
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,
)...