Re: [PHP] gallery (4 in a row) // carefull newbie

2004-12-28 Thread Robby Russell
On Tue, 2004-12-28 at 19:47 +0100, [EMAIL PROTECTED] wrote:
 Hi all
 
 I am making a gallery for my Homepage. Now, I want to make little 
 tumbnails of my work and make a table out of them. So, to not put them 
 all in a row, what whould make the site unreadable, i have to put them 
 in a little table, an i think 4 in each row would be ok.
 
 I like to read out the pic's name etc. out of a mysql table. But how do 
 make the script to write a /tr after it read out 4 entries of a mysql 
 table?
 
 Thanks in advance :)

I'd reply, but I don't think it would go anywhere: 
 [EMAIL PROTECTED] wrote:

-- 
/***
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON  | www.planetargon.com
* Portland, OR  | [EMAIL PROTECTED]
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting  Development
*--- Now supporting PHP5 ---
/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] gallery (4 in a row) // carefull newbie

2004-12-28 Thread Mike Johnson
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 

 Hi all
 
 I am making a gallery for my Homepage. Now, I want to make 
 little tumbnails of my work and make a table out of them. 
 So, to not put them all in a row, what whould make the site 
 unreadable, i have to put them in a little table, an i think 
 4 in each row would be ok.
 
 I like to read out the pic's name etc. out of a mysql table. 
 But how do make the script to write a /tr after it read 
 out 4 entries of a mysql table?
 
 Thanks in advance :)

What I generally do is use the mod (%) operator to keep track of where
it is. It returns the remainder of the divisional operator, as such: 

0 % 4 == 0
1 % 4 == 1
2 % 4 == 2
3 % 4 == 3
4 % 4 == 0
5 % 4 == 1
6 % 4 == 2
etc...  

That way, you have a guaranteed 4-member looping variable.

Try something like this:

?

$result = mysql_query(SELECT * FROM foo ORDER BY bar);

$count = 0;

while ($row = mysql_fetch_assoc($result)) {

$loopcount = $count % 4;

if ($loopcount == 0) {
echo tr\n;
}

echo td{$row['baz']}/td\n;

if ($loopcount == 3) {
echo /tr\n;
}

}

?

The only problem is that at the end of the while() loop, if you want to
have perfectly-formatted HTML, you need to figure out if it left off in
the middle of a row and fill with N empty td/td tags.

Also, if there's a better way to do this, I'm all ears. This is the way
I've done it for years, but it /is/ a pain to do.

Anyway, HTH!


-- 
Mike Johnson Smarter Living, Inc.
Web Developerwww.smarterliving.com
[EMAIL PROTECTED]   (617) 886-5539

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] gallery (4 in a row) // carefull newbie

2004-12-28 Thread John Nichel
Robby Russell wrote:
I'd reply, but I don't think it would go anywhere: 

[EMAIL PROTECTED] wrote:
So that's who has 'domain.invalid'.  Damn, I wanted to register that. ;)
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] gallery (4 in a row) // carefull newbie

2004-12-28 Thread Chris
Mike Johnson wrote:
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 

 

Hi all
I am making a gallery for my Homepage. Now, I want to make 
little tumbnails of my work and make a table out of them. 
So, to not put them all in a row, what whould make the site 
unreadable, i have to put them in a little table, an i think 
4 in each row would be ok.

I like to read out the pic's name etc. out of a mysql table. 
But how do make the script to write a /tr after it read 
out 4 entries of a mysql table?

Thanks in advance :)
   

What I generally do is use the mod (%) operator to keep track of where
it is. It returns the remainder of the divisional operator, as such: 

0 % 4 == 0
1 % 4 == 1
2 % 4 == 2
3 % 4 == 3
4 % 4 == 0
5 % 4 == 1
6 % 4 == 2
etc...  
That way, you have a guaranteed 4-member looping variable.
Try something like this:
?
$result = mysql_query(SELECT * FROM foo ORDER BY bar);
$count = 0;
while ($row = mysql_fetch_assoc($result)) {
$loopcount = $count % 4;
if ($loopcount == 0) {
echo tr\n;
}
echo td{$row['baz']}/td\n;
if ($loopcount == 3) {
echo /tr\n;
}
}
?
The only problem is that at the end of the while() loop, if you want to
have perfectly-formatted HTML, you need to figure out if it left off in
the middle of a row and fill with N empty td/td tags.
Also, if there's a better way to do this, I'm all ears. This is the way
I've done it for years, but it /is/ a pain to do.
Anyway, HTH!
 

Heh, that looks better than what I usually do, but to put a clean finish 
on it, you could do something like:

$loopcount = $count % 4;
if($loopcount  0)
{
   for(;$loopcount  4;++$loopcount) echo tdempty cell/td\n;
   echo /tr\n;
}
That should work, and could be cleaned up a bit better I imagine...
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] gallery (4 in a row) // carefull newbie

2004-12-28 Thread Matthew Weier O'Phinney
* Mike Johnson [EMAIL PROTECTED]:
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
  I am making a gallery for my Homepage. Now, I want to make 
  little tumbnails of my work and make a table out of them. 
  So, to not put them all in a row, what whould make the site 
  unreadable, i have to put them in a little table, an i think 
  4 in each row would be ok.
  
  I like to read out the pic's name etc. out of a mysql table. 
  But how do make the script to write a /tr after it read 
  out 4 entries of a mysql table?
  
  Thanks in advance :)

 What I generally do is use the mod (%) operator to keep track of where
 it is. 
snip
 The only problem is that at the end of the while() loop, if you want to
 have perfectly-formatted HTML, you need to figure out if it left off in
 the middle of a row and fill with N empty td/td tags.

 Also, if there's a better way to do this, I'm all ears. This is the way
 I've done it for years, but it /is/ a pain to do.

CSS and floats are your friend:

style!--
.gallery_image {
width: 200px;
float: left;
margin-right: 1em;
margin-bottom: 1em;
}
.clear {
clear: both;
margin: 0;
padding; 0;
height: 0;
}
--/style

!-- Loop over this, adding image sources and captions --
div class=gallery_image
img src=... alt=... /br /
caption here...
/div
!-- End of loop --
div class=clearnbsp;/div

The beauty of this method is:
* As the browser window expands, more images are allowed per row
* No need to muck about with closing rows
* Separation of content from layout

The cons:
* If you have some images landscape, some portrait, you may get some
  uneven spacing amongst rows. This can be solved by adding a height
  attribute to the style, but if your captions are of variable length,
  this could cause some strange display issues on longer captions.

-- 
Matthew Weier O'Phinney   | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist   | http://www.garden.org
National Gardening Association| http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php