SirChick Posted August 30, 2007 Share Posted August 30, 2007 Im trying find a way to do something like this: firstly this bit i can do but you need to understand what im on about: get all the rows.. and put the particular field values into an array lets say its just called "number". Now say there is 3 records with these numbers: record 1 = 1 record 2 = 10 record 3 = 4 Now what im trying to do is limit the amount of rows to 50. But each number must be unique but the user can pick the number so i cannot use auto increment plus the rows can be removed if the user deletes their number choice etc. The important thing though is this part.. im trying to basically once those 3 numbers are in an array.. try to take out those numbers from a value of 50. But what i don't want it doing is a subtraction. think of it like lottery numbers not like 50 subtract 4 subtract 10 subtract 1. Then when it finds the "remaining numbers" itll use that against the user's input for their number choice.. if the number is still remaining its available to use if not then its in use. Something like: 1 2 3 4 all the way to 50 then rid of 1 and 4 cos they are taken...and 10 Would i have to have one fixed array and one loading up the data from a table and then doing a comparison ? I was thinking ton's of if statements but there must be a quicker way? Quote Link to comment https://forums.phpfreaks.com/topic/67370-solved-is-there-a-php-feature-that-can-do-this/ Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 $nums = range(1,50); unset($nums[array_search($record1, $nums)]); unset($nums[array_search($record2, $nums)]); unset($nums[array_search($record3, $nums)]); print_r($nums); It should print out the remaining numbers. $nums will now be an array from 1-50 without the 3 records. Edit: of course, array_search is a lot of work for that. You could do a faster version like this: $nums = range(1,50); unset($nums[($record1-1]); unset($nums[($record2-1]); unset($nums[($record3-1]); print_r($nums); Since arrays start at 0. Quote Link to comment https://forums.phpfreaks.com/topic/67370-solved-is-there-a-php-feature-that-can-do-this/#findComment-338028 Share on other sites More sharing options...
SirChick Posted August 31, 2007 Author Share Posted August 31, 2007 how does that work exactly i don't follow how that's working. Quote Link to comment https://forums.phpfreaks.com/topic/67370-solved-is-there-a-php-feature-that-can-do-this/#findComment-338535 Share on other sites More sharing options...
AndyB Posted August 31, 2007 Share Posted August 31, 2007 how does that work exactly i don't follow how that's working. http://us3.php.net/manual/en/function.range.php http://us3.php.net/manual/en/function.unset.php Quote Link to comment https://forums.phpfreaks.com/topic/67370-solved-is-there-a-php-feature-that-can-do-this/#findComment-338550 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.