stylesheet problem

E

Els

Toby said:
brucie wrote:




And compute, say, 10 image sizes per page request? No thanks. I'd rather
not waste CPU cycles. Easier to compute once, store and retrieve. It's not
like they're going to vary much.

That's right, as far as the thumbnails go, they're either
100 x 70 px, or 70 x 100 px, most of them anyway.

What happened to the 'picture of a duck'?
It's not particularly beautiful, but it demonstrates the basic idea.

It does. Especially the fact that I can use a flat text file
for a database (I'm addicted to Notepad ;-)). So what does
MySQL have that a flat text file doesn't?
One thing though still hasn't been explained, nor by Brucie
or by you: How to have the different size thumbs vertically
centered, without the text beneath having influence on that.
Like this (now I'll have a go at using fixed width font):

---- ----
| | ------ | |
| | | | | |
| | ------ | |
---- ----
three
two oneline --
lines lines

(Note that the 'two lines' should be half a line up ;-))
There are a few obvious improvements, but they clutter up the example so I
leave them as an exercise for the reader. :)

I'm the reader ;-)
 
E

Els

brucie said:
In post <[email protected]>
Els said...




i would probably store in a DB the image name, page number, CSS file
name and text to go with that page number and the images. a single php
page could easily be used to display the "600 pages".

The css file is the same for all of them (if I find a way to
vertically and horizontally center any size picture without
using a one cell 100% table). I've had a look at Toby's
example, but I still don't see how to use one php file, for
600 pages, which are to be grouped in little numbers.
But I believe it's possible, because you say so, and so far,
I haven't seen you being wrong ;-)
So, even though I'm not saying I will build this site this
way, I still want to have a go at it. (You haven't convinced
me yet of this being easier/faster than the way I was doing
it, but you did convince me of there being a potential
possibility of php being 'cleaner', i.e. one page vs. 600 pages)

Next step: can you point me to a tutorial or specs that
explain the php principle? But from a beginners pov please.
Yes, I said I'm intelligent, but the easier it is, the less
I have to use my brain, and I'm lazy ;-)
The funny thing is, that for example Toby's example; if I
read the code, I more or less understand what it's saying
(except for some strange parts like (!feof($f)) and ('/\n/',
'', $buffer) ), but that's not exactly the same as
understand how to write it :-(
 
T

Toby A Inkster

Els said:
It does. Especially the fact that I can use a flat text file
for a database (I'm addicted to Notepad ;-)). So what does
MySQL have that a flat text file doesn't?

MySQL (or PostgreSQL or Oracle or... dare I say it... MS Access or SQL
server) allow you to make complex SQL queries.

For example, say I had a table of customers and I wanted to know the
postcodes and first names of every customer that had a surname "Smith" and
I wanted them sorted in reverse order by their postcode, but I only wanted
to see the first five items from that list, I could do:

SELECT firstname,postcode FROM customers WHERE surname='Smith' ORDER BY
postcode DESC LIMIT 5;

and it would return exactly what I needed.

For such complex queries it is usally much more efficient to use a
pre-made database system like MySQL than write all the data manipulation
routines yourself -- trust me, the clever people who make this sort of
software know a lot about optimising their routines!

So flat files are OK for some simple things like this, but for anything
more complex a proper SQL database is advisable. My site is backed by a
PostgreSQL database.

With regards to your earlier questions:

while(!feof($f))

$f is a reference to a file that I had opened earlier using the fopen()
function.

feof($f) is PHP-speak for 'we are at the end of $f' (EOF is a classic
programming abbreviation for 'end of file').

Putting an exclamation mark in front of it reverses the meaning -- so 'we
are not at the end of file $f'.

So the entire line means 'while we are not at the end of file $f' or in
more natural english 'do this until we reach the end of file $f'.

The other line you asked about was:

$buffer = preg_replace('/\n/', '', $buffer);

The PHP script had just read a line from $f and put it into $buffer.
(Things that start with $ are variables by the way). Now $buffer will
contain an end-of-line character. While this end-of-line character was
useful while it was in the database because it marked the end of one
record and the start of the next, we don't want or need it anymore.

preg_replace is a function that replaces parts of a string. In this case
it will replace the end-of-line character (\n) with a bit of nothingness.
 
T

Toby A Inkster

Toby said:
So flat files are OK for some simple things like this, but for anything
more complex a proper SQL database is advisable. My site is backed by a
PostgreSQL database.

Define "this":

The gallery. Not my Smith example.

Define my site:

The one linked to in my sig. Not the gallery.
 
E

Els

Toby said:
Els wrote:



MySQL (or PostgreSQL or Oracle or... dare I say it... MS Access or SQL
server) allow you to make complex SQL queries.

For example, say I had a table of customers and I wanted to know the
postcodes and first names of every customer that had a surname "Smith" and
I wanted them sorted in reverse order by their postcode, but I only wanted
to see the first five items from that list, I could do:

SELECT firstname,postcode FROM customers WHERE surname='Smith' ORDER BY
postcode DESC LIMIT 5;

and it would return exactly what I needed.

For such complex queries it is usally much more efficient to use a
pre-made database system like MySQL than write all the data manipulation
routines yourself -- trust me, the clever people who make this sort of
software know a lot about optimising their routines!

I should have guessed all this, really, I have (in a far
away past ;-)) used databases like Framework and Lotus and
.... I can't remember the names! But never used any
programming on them, except for getting addresses to end up
in letters, printed with Word Perfect. Don't even remember
how that worked ;-)
So flat files are OK for some simple things like this, but for anything
more complex a proper SQL database is advisable. My site is backed by a
PostgreSQL database.

A question about this. I understood from my provider, that I
could buy (rent?) a MySQL database on their server. But if
it's just a database, can't I upload it just like any other
file?
With regards to your earlier questions:

while(!feof($f))

$f is a reference to a file that I had opened earlier using the fopen()
function.

feof($f) is PHP-speak for 'we are at the end of $f' (EOF is a classic
programming abbreviation for 'end of file').

Putting an exclamation mark in front of it reverses the meaning -- so 'we
are not at the end of file $f'.

So the entire line means 'while we are not at the end of file $f' or in
more natural english 'do this until we reach the end of file $f'.

The other line you asked about was:

$buffer = preg_replace('/\n/', '', $buffer);

The PHP script had just read a line from $f and put it into $buffer.
(Things that start with $ are variables by the way). Now $buffer will
contain an end-of-line character. While this end-of-line character was
useful while it was in the database because it marked the end of one
record and the start of the next, we don't want or need it anymore.

preg_replace is a function that replaces parts of a string. In this case
it will replace the end-of-line character (\n) with a bit of nothingness.

Wow, you know how to explain things. You make PHP sound like
the old BASIC, of which I never understood what the
difficulty was. (Did never program anything more than a
'print only and all prime numbers, starting from 1'-routine
though) :)
You haven't written any php tutorial by any chance have you?
 
K

kayodeok

With regards to your earlier questions:

while(!feof($f))

$f is a reference to a file that I had opened earlier using the
fopen() function.

feof($f) is PHP-speak for 'we are at the end of $f' (EOF is a
classic programming abbreviation for 'end of file').

Putting an exclamation mark in front of it reverses the meaning
-- so 'we are not at the end of file $f'.

So the entire line means 'while we are not at the end of file
$f' or in more natural english 'do this until we reach the end
of file $f'.

The other line you asked about was:

$buffer = preg_replace('/\n/', '', $buffer);

The PHP script had just read a line from $f and put it into
$buffer. (Things that start with $ are variables by the way).
Now $buffer will contain an end-of-line character. While this
end-of-line character was useful while it was in the database
because it marked the end of one record and the start of the
next, we don't want or need it anymore.

preg_replace is a function that replaces parts of a string. In
this case it will replace the end-of-line character (\n) with a
bit of nothingness.

You have a nice way of explaining stuff.

If I had read a book or tutorial explained in this way, I wouldn't
have abandoned Perl or PHP or the other languages I have dabbled in
(currently eyeing up Python).
 
B

brucie

The css file is the same for all of them (if I find a way to
vertically and horizontally center any size picture

use php to work out what the top/bottom margins should be to
vertically align images of different heights.

(container height or max image height - image height)/2 = top and
bottom margins.

e.g. using the max image height of 100px:

(100-100)/2=0 (100-68)/2=16 (100-50)/2=25
+-------------+ +-------------+ +-------------+
| 100px image | | 16px margin | | 25px margin |
| 100px image | | 68px image | | 50px image |
| 100px image | | 16px margin | | 25px margin |
+-------------+ +-------------+ +-------------+
text for image text for image text for image

depending on the image height the margin value returned may not always
be a whole number but no one will notice an image 1px out of
alignment. use text-align:center to horizontally center the images
and text.
I've had a look at Toby's
example, but I still don't see how to use one php file, for
600 pages, which are to be grouped in little numbers.

i'm not sure what the "little numbers" are but you just suck the stuff
out of the database you need to generate each "page".

e.g. SELECT ImageName, ImageText (etc etc or just *) WHERE PageNumber='1'

use css and scripting to display the stuff sucked out of the BD. the
next/previous links (or whatever) just in/decrement the "PageNumber"
by 1. simple. or you could have WHERE DateOfPic or WHERE
Name='something' ORDERBY whatever. etc etc etc.

if you want to change the design you just change the css. you don't
have to re-do every page.
But I believe it's possible, because you say so, and so far,
I haven't seen you being wrong ;-)

you're not looking hard enough
Next step: can you point me to a tutorial or specs that
explain the php principle? But from a beginners pov please.

ummmmm

http://www.php.net/
http://www.zend.com/
http://www.sitepoint.com/
http://www.phpbuilder.com/
http://www.phpdeveloper.org/
http://php.resourceindex.com/
http://hotwired.lycos.com/webmonkey/programming/php/

dunno what any of them are like, i just read the manual
http://php.net/manual/en/index.php and google for "how the shpx do i
do..." if i'm stuck.
 
E

Els

brucie said:
In post <[email protected]>
Els said...




use php to work out what the top/bottom margins should be to
vertically align images of different heights.

(container height or max image height - image height)/2 = top and
bottom margins.

e.g. using the max image height of 100px:

(100-100)/2=0 (100-68)/2=16 (100-50)/2=25
+-------------+ +-------------+ +-------------+
| 100px image | | 16px margin | | 25px margin |
| 100px image | | 68px image | | 50px image |
| 100px image | | 16px margin | | 25px margin |
+-------------+ +-------------+ +-------------+
text for image text for image text for image

depending on the image height the margin value returned may not always
be a whole number but no one will notice an image 1px out of
alignment.

Of course, right now, having the pics centered in table
cells, they can't be positioned at 'half a pixel', can they?
use text-align:center to horizontally center the images
and text.

But this way, the text is outside the image-box, right?
i'm not sure what the "little numbers" are but you just suck the stuff
out of the database you need to generate each "page".

I meant "small numbers", and they are between 3 and 28
pictures per series/thumbnails page.
Not sure about the English in this case. Small numbers are
small amounts and little numbers are lady's dresses? Or is
that American 'English'?
e.g. SELECT ImageName, ImageText (etc etc or just *) WHERE PageNumber='1'

use css and scripting to display the stuff sucked out of the BD. the
next/previous links (or whatever) just in/decrement the "PageNumber"
by 1. simple. or you could have WHERE DateOfPic or WHERE
Name='something' ORDERBY whatever. etc etc etc.

Understood. I think.
if you want to change the design you just change the css. you don't
have to re-do every page.

Yes, that's the whole point ;-)
you're not looking hard enough

I'll look harder then ;-)

Thanks, I'll have a look at those, but just from having a
quick glance at this one:
http://php.net/manual/en/index.php and google for "how the shpx do i
do..." if i'm stuck.

I think that one just might suffice.
Thanks again, I'll be back when I run into questions.

Hang on, I won't. I guess I'd have to go to alt.php then. ;-)
 
B

brucie

In post <[email protected]>
Els said...

But this way, the text is outside the image-box, right?

+----container----+ +----container----+ +----container----+
| +-------------+ | | +-------------+ | | +-------------+ |
| | 100px image | | | | 16px margin | | | | 25px margin | |
| | 100px image | | | | 68px image | | | | 50px image | |
| | 100px image | | | | 16px margin | | | | 25px margin | |
| +-------------+ | | +-------------+ | | +-------------+ |
| text for | | text for image | | text for image |
| image | | | | |
+-----------------+ +-----------------+ +-----------------+

set the height of the container large enough to accommodate the text
for the image if its resized (a reasonable amount) or wraps to more
than one line. float the containers left. if the container is set to
20% width you'll fit 4 across the page evenly spaced with them
automatically wrapping when required. if you have the containers set
to 150px width you'll fit as many was the window width allows with
them automatically wrapping when no more will fit the window width
whatever it may be.

easy peasy.
 
E

Els

brucie said:
In post <[email protected]>
Els said...





+----container----+ +----container----+ +----container----+
| +-------------+ | | +-------------+ | | +-------------+ |
| | 100px image | | | | 16px margin | | | | 25px margin | |
| | 100px image | | | | 68px image | | | | 50px image | |
| | 100px image | | | | 16px margin | | | | 25px margin | |
| +-------------+ | | +-------------+ | | +-------------+ |
| text for | | text for image | | text for image |
| image | | | | |
+-----------------+ +-----------------+ +-----------------+

set the height of the container large enough to accommodate the text
for the image if its resized (a reasonable amount) or wraps to more
than one line. float the containers left. if the container is set to
20% width you'll fit 4 across the page evenly spaced with them
automatically wrapping when required. if you have the containers set
to 150px width you'll fit as many was the window width allows with
them automatically wrapping when no more will fit the window width
whatever it may be.

No, I'll use absolute positioning for now, to not have them
all lined up in a grid. But I'll keep this floating stuff in
mind if I end up with flexible design later on ;-)
easy peasy.

A "box" (image with margins) in a box. Now why didn't I
think of that...
Thanks ;-)
 
B

brucie

if the container is set to 20% width you'll fit 4 across the page evenly
spaced with them automatically wrapping when required.

that should probably be 5 across if you're from the planet locally
known as earth. <dribble/> <twitch/>
 
T

Toby A Inkster

Els said:
Wow, you know how to explain things. You make PHP sound like
the old BASIC, of which I never understood what the
difficulty was. (Did never program anything more than a
'print only and all prime numbers, starting from 1'-routine
though) :)

Well PHP is somewhere between BASIC and HTML. :)

PHP is a full-featured programming language (like BASIC, Java, C++, Perl,
etc) that is mainly geared at outputting HTML. (Although it can
theoretically output data in any format.)

(As an aside, I once wrote an entire online message board system using
QBASIC. It was one of my first attempts at CGI programming. I wish I could
find the source code.)
You haven't written any php tutorial by any chance have you?

I only consider myself a newbie in PHP. :)

I have a Comp Sci degree, so am pretty good at programming techniques, but
I don't know much of the specifics of PHP. I have to constantly refer to
the online manual and copy and paste bits of code from my earlier attempts.
 
I

Isofarro

Toby said:
PHP is a full-featured programming language (like BASIC, Java, C++, Perl,
etc) that is mainly geared at outputting HTML. (Although it can
theoretically output data in any format.)

Not theorectically. XML is no problem. I'd be surprised if there was any
textual format PHP couldn't do. Then again, there's nothing preventing it
from returning any binary format too - e.g. PHP graphical counters.
 
T

Toby A Inkster

Isofarro said:
Not theorectically. XML is no problem. I'd be surprised if there was any
textual format PHP couldn't do. Then again, there's nothing preventing it
from returning any binary format too - e.g. PHP graphical counters.

Precisely. I have output spreadsheets and even graphics with PHP, but it
is not fun. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,207
Latest member
HelenaCani

Latest Threads

Top