phpmysqlfreak Posted November 17, 2009 Share Posted November 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/181804-random-word-php-and-mysql-application/ Share on other sites More sharing options...
waynew Posted November 18, 2009 Share Posted November 18, 2009 By placing a user_id in the words column and then linking that word back to the specific user? I'm not 100% sure what you're talking about. Quote Link to comment https://forums.phpfreaks.com/topic/181804-random-word-php-and-mysql-application/#findComment-960335 Share on other sites More sharing options...
plznty Posted November 21, 2009 Share Posted November 21, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/181804-random-word-php-and-mysql-application/#findComment-962314 Share on other sites More sharing options...
ngreenwood6 Posted November 21, 2009 Share Posted November 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/181804-random-word-php-and-mysql-application/#findComment-962317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.