0

This table is inside a database

  TID         Products
   1           1,2,5 
   2            2,4 
   3            2,3 
   4           1,2,4 
   5            1,3 
   6            2,3 
   7            1,3 
   8          1,2,3,5 
   9           1,2,3 

this table is created by combinations of itemsets, for now only 2 itemsets but eventually 3, 4, 5 and so on. As you can see the Sup count counts the coincidences in the Products table of the Itemset that is in that row.

ItemSet     Sup. count 
  1,2            4 
  1,3            2 
  1,4            0 
  1,5            0 
  2,3            4 
  2,4            2 
  2,5            1 
  3,4            0 
  3,5            1 
  4,5            0




for($i = 0; $i < $count_itemsets; $i++){
    for($j = 0; $j < $count_productrow; $j++){

        $string = $productrow[$j];
        $myArray = explode(',', $string);

this turns the string into an array example the first product {1,2,5}

        $arr_expl_itemset = explode(',',$itemset[$i]);

this explodes itemset to also make it into an array example the first ItemSet row {1,2}

        $count_explode = count($arr_expl_item);

this counts the length of the new array $arr_expl_itemset

        for ($x = 0; $x < $count_explode - 1; $x++){
            array_splice($arr_expl_item,$count_explode - 1,0,"&");
        }
        echo $arr_expl_item;

this for loop is where I want to add new elements without erasing the old ones. The new element that I want to add is the ampersand to make a array that looks like this:
1 & 2 & 5 that is why I am counting the array to minus 1 so that the last element is not an ampersand. All this to then convert to a string which would be $arr_expl_item_STRING = 1 & 2 & 5; this is where I am stuck. I don't really know if this would work with preg_match but I've been reading and to do an OR statement the code would be like this:

/*if(preg_match("/(bad|naughty|other)/i", $data)){
 //one of these string found
}*/  

So I was thinking if I wanted to do a comparative with AND I would do it the way that I explained before.

        if (preg_match('/($arr_expl_item_STRING)/i', $string, $m)) {
            $result_support[$i] = $result_support[$i] + 1;

I want to count the numbers in the array so that i can look for {1,3} in the products column where the string is {1,3}, {1,2,3}, {1,2,3,5} and so on. if I do a boundary to look for a specific substring the matches will not work and if I look for coincidences it wont work when I get to two digit numbers like 12 or more since 1 and 2 would be found again.

        }
    }
}
student
  • 39
  • 4
  • 2
    Side note: I would encourage you to read [SQL Antipatterns: Avoiding the Pitfalls of Database Programming (Pragmatic Programmers)](http://www.amazon.com/SQL-Antipatterns-Programming-Pragmatic-Programmers/dp/1934356557) – HamZa Dec 11 '14 at 11:40
  • Why don't you use `implode(' & ', $arr_expl_item)`? – Barmar Dec 11 '14 at 11:40
  • `&` doesn't work in a regular expression to match all the patterns. See http://stackoverflow.com/questions/18496715/javascript-regular-expression-that-matches-two-strings/18496791#18496791 for how to write a regexp that matches all of several strings. – Barmar Dec 11 '14 at 11:48
  • Instead of using regular expressions, explode the strings into arrays. Then use `array_intersect` to see if all the elements of one array are in the other array. – Barmar Dec 11 '14 at 11:49
  • now I want to know if my preg_match syntax is correct. The implode helped @Barmar. – student Dec 11 '14 at 11:58
  • Yes, the first argument is the regexp, the second argument is the string to match, and the third argument is the variable to hold the match results. So your calling syntax is correct. Without seeing the contents of `$arr_expl_item_STRING` I can't tell if your regexp is correct. – Barmar Dec 11 '14 at 12:05

0 Answers0