Probably stupidly easy problem

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Probably stupidly easy problem

Postby andychannelle » Sun Aug 13, 2006 11:54 am

Back in programming school, I never really got beyond HTML, and now I'm faced with a problem I just can't solve, so if any of you smart people can help me out that would be great!

I have a list on a website and I want to set it so that once an item is selected from the list, it becomes unavailable to other visitors. Does this sound easy with HTML/Javascript/PHP/Something else or - dan dan daaaaan - will it require the use of a database?
andychannelle
LXF regular
 
Posts: 111
Joined: Mon Apr 04, 2005 4:08 pm

Postby TheDoctor » Sun Aug 13, 2006 7:23 pm

A few basics to guide you to the right answer (in the spirit of teaching a man to fish):

- HTML is not a programming language but a markup language. That means you can't use it for processing. So it's no good for your purposes.

- Javascript is a programmig language, but it executes on the client side - ie it runs on the user's PC. This means it is useful if you had a list and wanted the user's browser to do something special if/when they picked an item. But it can't affect anything that happens on another user's PC. So that's a no-no for you.

- PHP is a server-side programming language, and therefore anything it does applies to all users. You could certainly use it for what you want to do, but you'd have some means of storing which items had already been chosen. Which means you're right: you're going to have to use a database as well.

Hope this makes things clear, even if it confirms that things may mean more work than you'd hoped.
TheDoctor
LXF regular
 
Posts: 325
Joined: Mon Jan 02, 2006 9:02 pm

Postby nordle » Sun Aug 13, 2006 11:11 pm

Just to throw a couple of things, the database could be sqlite or java hsqldb so its really tiny.

But also, could you (if there are not too many) not store the values in a simple .txt file, then just do some text file manipulation via php?
I think, therefore I compile
User avatar
nordle
LXF regular
 
Posts: 1500
Joined: Fri Apr 08, 2005 9:56 pm

Postby jjmac » Mon Aug 14, 2006 2:20 am

Something like a conditional expression using a flag to lock it. The flag gets set if it hasn't been selected before and allows the process into the conditional to return the value. It gets unset when unselected. If the flag is set on another attempt to retrieve it, it returns with a not available message ... something along those lines. I'm thinking in C though :)

jm
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia

Postby nelz » Mon Aug 14, 2006 7:47 am

You'd need a way to store the flags, which could be a database but a simple file with one item per line would do just as well. Use PHP's ereg() function to check whether each item is in the list.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8577
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby andychannelle » Mon Aug 14, 2006 9:05 am

My fears confirmed. Thanks for the advice. I'll get a book on MySQL/PHP...

Thanks
andychannelle
LXF regular
 
Posts: 111
Joined: Mon Apr 04, 2005 4:08 pm

Postby nelz » Mon Aug 14, 2006 9:17 am

I use Professional PHP Programming from Wrox. I've had it several years, so it's a bit out of date now but I expect there's an updated version. I had all I needed on MySQL as well as PHP.

But I think an SQL database is overkill for a simple item list, a text file should do.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8577
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby ollie » Mon Aug 14, 2006 9:39 am

I have taught PHP - MySQL for a number of years and the best text book is PHP and MySQL Web Development by Laura Thomson & Luke Welling. It's now in third edition and you have to put up with US spelling, even though it is written by two Australians :? , and deals with creating and editing text files using PHP.

There would be nothing wrong with using PHP to edit the file containing the list to remove the radio button in the code. It might be a bit of work but careful planning and the use of variables would avoid having to setup a database to manage this.
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests