B
brucie
do they still call it the information super highway?
that would be funny if it wasn't so sad. "information super highway"
is mentioned in the site text.
do they still call it the information super highway?
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.
It's not particularly beautiful, but it demonstrates the basic idea.
There are a few obvious improvements, but they clutter up the example so I
leave them as an exercise for the reader.
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".
Toby said:Els wrote:
That is a very basic function that PHP can do, but it is capable of so
much more!
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?
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.
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!
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.
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.
The css file is the same for all of them (if I find a way to
vertically and horizontally center any size picture
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 ;-)
Next step: can you point me to a tutorial or specs that
explain the php principle? But from a beginners pov please.
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.
use text-align:center to horizontally center the images
and text.
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.
you're not looking hard enough
http://php.net/manual/en/index.php and google for "how the shpx do i
do..." if i'm stuck.
But this way, the text is outside the image-box, right?
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.
easy peasy.
if the container is set to 20% width you'll fit 4 across the page evenly
spaced with them automatically wrapping when required.
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)
You haven't written any php tutorial by any chance have you?
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.)
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.
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.