FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
Unique Combinations Script
Message  

Reply with quote
Post Unique Combinations Script 
Code:

$model_total = 14;
$model_array = array();

// Step One: Fill an array with each model number
for($x = 0; $x < $model_total; $x++) {
   $model_array[$x] = $x+1;
}

// Step Two: Fill another array with combinations
$model_com = array();
$counter = 0;
$count = 0;

for($x = 0; $x < $model_total; $x++) {

$model_com[$counter] = $model_array[$x]."<BR>";
$counter++;

   for($length = $x+1; $length <= $model_total; $length++) {
      
      for($reps = $length; $reps <$model_total; $reps++) {
         $count++;
         $model_com[$counter] = $model_array[$x];
         for($con = $x; $con < $length; $con++) {
            $model_com[$counter] .= $model_array[$count+$con];
         }
         $model_com[$counter] .= "<BR>";
         $counter++;
      }
      $count = 0;
   }
}

// Step Three: Echo All Possible Combinations
$mc_size = count($model_com);
for ($x=0; $x < $mc_size; $x++){
echo $model_com[$x];
}


View user's profile Send private message

Reply with quote
Post  
This script takes any number within reason and fills an array with each number value. In the script we use 14 different numbers ranging from 1 to 14. But this can be changed.

The next step is to produce every combination without redundancy and fill another array with the combinations of the first array. This is where is gets tricky, because what happens here is that the combinations are dependent on the order of the first array. This is actually how it is supposed to work.

Finally we output all the combinations to screen just to check that the script is working.

You may wonder why I needed this script - but here is a real life example;

I have 14 glamour models each with their own name. I use a <SELECT MULTIPLE> option in a HTML form where the user can select any combination of models to look at...The models are listed in a specific order in the SELECT tag so the order does not change, only the possible combinations. Hence the need for the script to be dependent on the order of the input values.

There cannot be any redundancy, and there is not! For example, since the user can only select model 1 once, there is no use for model 1 to be listed twice in one combination such as 112. Therefore there is no redundacy in that matter.

I used the output to fill a database with all combinations (over 200 for 14 models) so I can have a list of combinations to create statistics with and had a model List ID attached to each model combination.

I soon thought about other ways I could use such a program, but one program I am working on at the moment is to expand the combinations to include all possible variations of the SELECT model list. That part is pretty tricky as it took me two days and 1 failed attempt to actually code this script to produce the exact output needed. I feel I could replace the counters with more loops but then it may get confusing...

catcalls
robbiedave.com

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com