1

i am pretty new to html and as part of project we have to create a game where the player has to select different tags and then gets rewarded according to a value which is stored in a .csv file. I created the layout so far with diffrent buttons, now i want to know how can i search inside the csv file and return the corresponding value? I am using html and javascript so far.

There are about 6000 entries in this file. Is it wise to load them all into an array?

And how can i share variables between functions without calling them one after the other? For example to find out how often a button was pressed i obviously could not use a var in a script since it would be lost after the script was executed so i had to create a html input text field to store the variable constantly.

Your help is appreciated :)

Regards, Marcurion

1 Answer 1

1

It would be wise to use a DBMS, however if the project requirement is to use CSV you could use a server side programming language like PHP to read and write the CSV file.

I wouldnt recommend to load all entries in the array, instead you could only load what you need but this can be achieved by using a DBMS.

To share variables between functions on javascript you will need to declare them as global variables, you could google: "javascript variables scope" or "javascript global variables" and read a little more of scopes.

If you want to know how often the button was pressed you can make AJAX requests to a server side script that can handle what you need if the script needs to be submited or executed.

You could check out JQuery framework to use events, ajax and infinite other things.

My advice is for you to read a little more about javascript, a framework for javascript like JQuery and a little of server side languages like PHP, with these tools you can easily develop what you need.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your quick and helpful response, one more thing: Would it be possible with php to search the csv file with php or would i have to load the entire file or can this only be done by a DBMS?
Hi, there are no php propietary functions that will make an exact search, if you really need use a csv the you will have to load all of its data with a read function like this one php.net/manual/en/function.str-getcsv.php then you can make some sort of function that searchs in the array. I advice you to use a DBMS to store information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.