jessl1905 Posted August 17, 2011 Share Posted August 17, 2011 I'm not a coder unfortunately, however, I am trying to work out the best way (and to learn how to) have data inputted into the mysql database at random. ie: There is 100 rows in the Database (pre-created to have values in a second column). I enter a name using a form and it inserts the name into a random row in the first column, only if that row is empty. If the row is not empty and it hasn't gone through all the 100 rows, continue checking and then insert once there's an empty row. If it has checked all 100 rows and they're all full, alert or echo with "Database is full!". Or would it be better for me to do this on the PHP side, where the randomness is done there and then inserted into the database? Any help with this would be much appreciated! Ta Jess Link to comment https://forums.phpfreaks.com/topic/244969-easy-php-mysql-question-just-not-easy-for-me/ Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Your logic is a little crazy here. Why not just keep adding users to the database until you've reached 100? Keep the values you'd have in the second column in a separate table, and combine them when you need to make pairs. Once you've hit 100 entries in the database, just return the 'DB is full' message until that number drops. Link to comment https://forums.phpfreaks.com/topic/244969-easy-php-mysql-question-just-not-easy-for-me/#findComment-1258378 Share on other sites More sharing options...
jessl1905 Posted August 17, 2011 Author Share Posted August 17, 2011 Thank you xyph! Makes perfect sense. So if I create the table 'users' (which is empty) and create another table 'number' (100 rows with values), how could I use PHP to go: on submit, insert a new user (name as the input) into 'users', get a random value from 'number' and assign it to the user, mark that value from 'number' as "used up so no other name can get that value", and stop running all this once the 100 users have been added. It's quite confusing for me to understand how to do this in PHP.. Thank you again for your help, I really appreciate it!! Link to comment https://forums.phpfreaks.com/topic/244969-easy-php-mysql-question-just-not-easy-for-me/#findComment-1258398 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Don't worry about giving a user a random number until you want to use that information. If you told me, in a broader sense, what you're trying to accomplish, I could help further. Ideally, when you want to give the users a random number, you'll grab all the users into an array, all of the numbers into an array, shuffle one of them, and combine. I'll start providing some coded examples once you start showing us some coded attempts. Link to comment https://forums.phpfreaks.com/topic/244969-easy-php-mysql-question-just-not-easy-for-me/#findComment-1258663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.