Question: I have put together a very complicated search form. Using arrays I have managed to get it searching by checkboxes. 

```
if(isset($_POST['search']) && !empty($_POST['search'])){
foreach($_POST['search'] as $key=>$value){
    if($value==1) $search[] = "$key";
}
$searchstring = implode(' AND ', $search);

```

}

```
        $query = "SELECT candidate_id.master_id, candidate_contact_details.first_name, candidate_contact_details.last_name, candidate_contact_details.home_phone, candidate_contact_details.work_phone, candidate_contact_details.mobile_phone, candidate_contact_details.email FROM candidate_id, candidate_contact_details, qualifications, security_experience, previous_career WHERE qualifications.active = 'finished' and candidate_id.master_id = candidate_contact_details.c_id and candidate_id.master_id = qualifications.c_id and $searchstring";

```

I know how to do searches of the database by a specific term. ie. postcode field but does anyone know how I can add that to this query? I know how to do either checkbox based searches or text field based searches but cannot figue out how to combine the two.

Thanks Again
Jason

Answer: 
OK, I think I found a very short way of doing this (only 1 line for the for loop):

```
var arr = [1,2,3,4,5,6,8,10,12,13,14,15,20,21,22,23,24,25,26,27,28,29,30];
var res = new Array();
res[0] = 0;

for(var i=1;i<arr.length;i++) res[i] = (arr[i] == arr[i-1] + 1) ? (res[i-1] + 1) : 0;

var maxLength = Math.max.apply({},res);

```

this gives you (10) as the result. if you need (11) (which makes more sense) change the 0 to 1 in the for loop.

jsFiddle link: <http://jsfiddle.net/gEzzA/8/>
Here's the solution in pseudo code... 

First, setup another array with the same number of elements and initialised to zero, to use as counters...

```
Array01:=[1,2,3,4,5,6,8,10,12,13,14,15,20,21,22,23,24,25,26,27,28,29,30]
Array02:=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

```

Now the logic for filling in the counters...

```
FOR i:=0 TO LastElement DO 
 WHILE (Array01[i+1]-Array01[i]=1) AND (i<LastElement) DO Inc(Array02[i]);

```

Now to scan who's got the highest sequence score...

```
which:=0; Value:=Array02[0];
FOR i:=0 TO LastElement DO 
 IF Array02[i]>Value THEN BEGIN Value:=Array02[i]; Which:=i; END;

```

So, at the end of this the highest sequence is held by Array element "Which" and the count is "Value"!