Some quick advise on what to use

mrk

mrk

Man of Honour
Joined
18 Oct 2002
Posts
105,023
Location
South Coast
Hey guys, I'm more of a html kind of person so have little experience witht his kid of thing and wanted to get some advice on how best to go about the below task.
Once I have an understanding of how to start it I guess I can go from there or if there is any free code out there that can be tailored to your own needs then that would be great.

Basically imagine on a page you have a number of buttons (or images) that can be clicked.
When visitor A clicks a button/image 5 times the button will move along say 20 pixels towards the right each time on the page.

^This is all fine, this can be implemented easily no probs.

The part where I'm stuck is how would you save this information so that if visitor B comes along and clicks the same button a further 5 times that it moves again the same amount but of course from the position that visitor A left it?

I'm guessing databases are going to be involved here?

ANy help would be appreciated :)
 
yeah some sort of persistent storage will be required. However, you will find that you have some trouble with concurrency - what happens if you and I both load the page at the same time when the button is at position 0.

I click the button 20 times moving it 80 pixels to the right.

You click the button 10 times moving it 20 pixels to the right.

Either way you will have missed some clicks. You could force the page to reload every minute, say, in which case you might not miss as many clicks but it still isn't perfect.
 
I too was thinking this, it doesn't work the same way as a hit counter so would be visitor specific not globally specific.

Do you reckon it would be more accurate in a flash applet instead? Given the above info you've confirmed I reckon it's going to be bound by the same limitations though.

Hmm
 
It will be the same in flash unfortunately. I'm not sure the best way to do something like this, not even sure its possible. I would like to hear other peoples thoughts though.
 
To do it per user cookies are the answer. To do it for globally, I would disable the button with js when it is clicked do the processing and the reload the page. As for storing it with issues of concurrency, i would put it in a database then do the update with a stored proc, locking the row i was working on and wrapping the whole thing in a transaction. Or write a small php script to store it in a text file and just have it hang arround untill it can get a lock on the file.
 
Database, cookies/sessions are very viable option.

Or use AJAX and store the position in an XML file and the position will update with having screen refresh?
 
yeah but both ways are going to have to rely on refreshing the page constantly to redraw the button in case another user has moved it. This obviously becomes a strain on the server when lots of users are refreshing the page at a given interval.
 
Yeah, I understand it is possible I'm just saying there isnt a nice way of doing it. You still have to actively query the server to find out if it has moved which is not nice.
 
Yeah, I understand it is possible I'm just saying there isnt a nice way of doing it. You still have to actively query the server to find out if it has moved which is not nice.

I think AJAX is a good way of doing it. Making an asynchronous XML HTTP request uses a lot less bandwidth than a synchronous HTTP request. Why is requesting info from a server a bad thing? That is what they are there for.
 
its not a bad thing in most cases but in this scenario it would be far more suitable if the 'client' could listen for events on the 'server', I just think that this sort of thing on a webpage is troublesome - however, I have never created an ajax page so don't know how effective it is, I would like to see an example of this if you ever get round to creating it.
 
Thanks guys, I'll have a ponder around and see what can be done, I may well be back!
 
its not a bad thing in most cases but in this scenario it would be far more suitable if the 'client' could listen for events on the 'server', I just think that this sort of thing on a webpage is troublesome - however, I have never created an ajax page so don't know how effective it is, I would like to see an example of this if you ever get round to creating it.

I am interested to know how you would achieve the above without making an synchronous HTTP request?

AJAX is effective for most applications. I code finanical trading systems and AJAX couldn't cope with this and we abandoned it in favour of .NET. I think this is exceptional give the amount of request it had to service. I think you reason for not using AJAX is unfounded.
 
sorry, I seem to be confusing you (and me)! I'm not saying dont use AJAX - it is in fact the best solution to the problem - I am just saying that it wont be as fluid as a standalone application, which is a compromise you have to make when dealing with web technologies.
 
Back
Top Bottom