TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

Text file database/parameters/variables question(s)

Page: 1 Reply
Aug 20th 2004#158837 Report
Member since: Nov 18th 2002
Posts: 267
Hello,
I'm just getting started with PHP (4) and the only thing I really need to do right now is grab information from a text file, but I can't find anywhere with code snippets or tutorials that are doing what I want to do, they're always more complicated than necessary.

Anyway, my site (sparktasty.net) has loads of wallpapers that I've made on it and at the moment when you click a thumbnail, the preview pops up in it's own window which looks quite ugly. I wanted to have a "template" page and load that each time, but grab the details of the image from a textfile and make the template complete, ie, fill it in with information.

I wanted to parse the link like this:
[HTML]Test Image Link[/HTML]

and when that PHP page loads, have it read variables from a text file with the name of the variable in the link (testimage). So "testimage.txt" would look something like this:
[HTML]
imagename=Test Image
birth=25/12/1999
app=Photoshop
comment=This is some random blurb for an image that doesn't even exist
[/HTML]

Is my question clear?

If anyone has any helpful hints and/or links, please post.

ThanX, BYEEEEE!!
Reply with Quote Reply
Aug 20th 2004#158844 Report
Member since: Feb 18th 2004
Posts: 736
For that, you would probably find it easier to use a mySQL database instead of seperate textfiles for each image.
You won't have trouble finding a tutorial on how to retrieve information from a mySQL database with php ;)
Reply with Quote Reply
Aug 20th 2004#158849 Report
Member since: Nov 18th 2002
Posts: 267
But I want complete control and since I'm new to all this, I'd rather just use text files which can be edited/created/etc from any computer with any OS.

Also, I have a client (I feel weird using that term) who wants the same sort of functionality as I need for my site and he'd like to be able to update it easily himself and text files seem like the answer for him anyway.

ThanX though, but does anyone know specifically about text file usage?

BYEEEEE!!
Reply with Quote Reply
Aug 20th 2004#158854 Report
Member since: Nov 26th 2001
Posts: 2586
[QUOTE=devlkore]But I want complete control and since I'm new to all this, I'd rather just use text files which can be edited/created/etc from any computer with any OS.
[/quote]

if you are using a database on your webhost all you have to do is log into phpMyAdmin and use a gui to add/edit your databases.

Also, I have a client (I feel weird using that term) who wants the same sort of functionality as I need for my site and he'd like to be able to update it easily himself and text files seem like the answer for him anyway.


Learn to make a simple form that will take in the info and allow him to update the database.

As far as text files go. Its going to involve the same amount of work if you used a database or if you use textfiles. Unless you want to edit the text files on your own computer and then upload them. Might be easiest that way. But to actually open the file and edit it using an html form and php will be just as much work as to do the same thing with mysql and a lot less efficient in runtime.
Reply with Quote Reply
Aug 20th 2004#158856 Report
Member since: Apr 20th 2002
Posts: 3000
Don't bother putting in imagename, birth, etc. Omit the labels and just have:

Test Image
25/12/1999
Photoshop
This is some random blurb for an image that doesn't even exist


then to grab the information, just do

[PHP]
list($filename, $birth, $app, $comment) = file("testimage.txt");[/PHP]
To go more in depth, the file function grabs information from the given text file, testimage.txt, and returns an array where each line is an item in the array. Order is preserved of course. The list fucntion will assign the given variables, $filename, $birth, $app, $comment, with the associated value in the array.
Reply with Quote Reply
Aug 21st 2004#158867 Report
Member since: Nov 18th 2002
Posts: 267
ThanX everyone (especially !mo0chan!), that is basically what I wanted.
Eventually I'll move up to using databases, but since I've never used PHP before, I thought I'd start off keeping each thing to a minimum, so not using databases is preferable at the mo'.

Anyway, ThanX for everyone's help, although if anyone has anything to add, feel free.

BYEEEEE!!
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum