Jump to content

Recommended Posts

I am fairly new to PHP and MySQL and wanted to learn more by making a useful random word application with its definition, part of speech, sample sentence, definition, ect. to get better with SAT vocabulary (I'm 16 years old).

 

Anyways, I have all that working, plus a basic search function and related words function, but as I only have 10 words in the table at this time, I'm getting repeat words. I only plan on having 1000 words, so there is still a change of getting repeat words.

 

So my next goal with this basic application is to make a system that doesn't repeat words until all words have been displayed. I know I could make a field in the table with a default value of 0, and change it to 1 if its been displayed, but then it wouldn't be displayed again for any user until all users have visited every single word. Not good.

 

Another idea I had was to store the id's of each word that has been used already and storing it in an array in a PHP file and cross-checking that array before choosing the word to be displayed. Once again, this would be a non-user specific system...

 

SO...my question is...How can I create a system that is user-specific (only affects one user using the application at a time) that doesn't repeat any already used words...

 

THANKS!!!

 

-Adam

Link to comment
https://forums.phpfreaks.com/topic/181804-random-word-php-and-mysql-application/
Share on other sites

Hey there. I don't know how you would go about getting definitions but I'll answer the question you have asked.

COLUMN 1 - WORD ID

COLUMN 2 - WORD

COLUMN 3 - WORD DEFINITION

COLUMN 4 - ACTIVE

 

Make it so on load it makes column 4 turn into a 0 instead of a 1.

1 being words that havent yet been seen and 0 being words that have been seen.

Then use a random generator to select from WHERE COLUMN 4 = 1, then to make it from 1 to a 0.

 

I hope this helped alot!

If you are using a login system you can create a new table for the viewed words and each time they view a word it inserts it into that table with there user id. Then when the user comes there check that table against the words and only show ones that arent in the table.

 

If you arent using a login system you can do it based on sessions. When the user comes to the site (having session_start() on the page) you would insert the session id into the new table like above and insert the word into that table. Then you could check the words against the database based on the users session id. You could also look into serialize() and unserialize(). That way in the table you wouldnt have to insert a new row foreach word. You could just create one row for the session id and then serialize the data and put it into one field. Then when you want to read it back you can use unserialize and get it into an array. Then you can use array_push() to insert the word they just got into the array and then serialize the new array and update the database. I would suggest this method anyways because each time the user comes to the site it will give them a new session id and therefore put all the words ready for viewing again.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.