Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a site in which user can choose three programmes between 9. I would like to have a view that gives me the 6 programmes a user didn't choose. I've created programmes using taxonomy so each of my users have a term reference on programmes that contain the 3 programmes.

Any idea would be appreciated, Thanks

share|improve this question
1  
Have you looked at the Views Raw SQL module? –  Triskelion Feb 26 '13 at 21:36

1 Answer 1

Forget the Views Raw SQL module. Simple SQL is not going to give you the result you need. Queries look for what is there, not what isn't.

You will need to construct two lists. First, the list of programmes the user has selected.

$selected_programmes = array();

foreach ($user->field_taxonomy_programme['und'] as $selected_programme) {
  $selected_programmes[] = $selected_programme->name;

}

Second, the list of available programs.

$available_programmes = array();

$vocabulary = taxonomy_vocabulary_machine_name_load('programmes');

$programmes = taxonomy_get_tree($vocabulary->vid);

foreach($programmes as $programme) {

  $available_programmes[] = $programme->name;

}

Then you can use the two lists to produce a list of the unselected programmes, which can then be used to construct your query.

$unselected_programmes = array_diff( $available_programmes, $selected_programmes);

There is no way around it. The only way to construct a query for values which are not present is programmatically. I would suggest the use of a block with a php snippet to display this information.

share|improve this answer
    
I'm that isn't true- surely they can just use the NOT IN (SELECT...) subquery syntax? –  cjm2671 Jul 8 '13 at 23:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.