Thursday, July 30, 2009

Reading Large Data Files For PHP? (not a database)?

Hey,


I am writing a board game in php where the players are asked questions about shakespear (not my idea!). I am looking for an alternative way of reading in the questions other than database and just inserting into the php file. I was thinking maybe XML? like:


%26lt;list%26gt;


%26lt;question%26gt;Here is a question, the answer is b!%26lt;/question%26gt;


%26lt;correct%26gt;b%26lt;/correct%26gt;


%26lt;question%26gt;Here is a question, the answer is c!%26lt;/question%26gt;


%26lt;correct%26gt;c%26lt;/correct%26gt;


%26lt;/list%26gt;


The php file will then choose one of the 15 or 20 questions (there are 20 easy 20 medium and 15 hard(dependant on certain elements in the game wether a random hard or easy is chosen)) Hope you can help!!


Thanks in advance

Reading Large Data Files For PHP? (not a database)?
You might consider creating a class for your question objects, create the instance for each one and then use serialize to stash the instances in a file:





http://ca.php.net/manual/en/function.ser...





HTH! Just remember: before you can read the objects into a real program you have to run the class definition.





Or, you COULD just write the class definition along with the questions in a separate PHP file. Use the require or require_once command to load that file:


http://ca.php.net/manual/en/function.req...








By the way, this *does* run afoul of your "not a database" comment, technically. A database is ANY collection of data; a shopping list on a discarded homework sheet is an example of a database, strictly speaking. I assume you really mean "not in a RELATIONAL database", which is much, much more specific.


No comments:

Post a Comment