Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a the following query:

function background_audio_file_query($path) {
  $result = db_query("SELECT uri
    FROM `file_managed`
    WHERE `filemime` = 'audio/mpeg'
    LIMIT 1 , 30",
    array(':uri'=>$path))->fetch();

return $result;
}

How can I pass this to a Drupal variable? I am assuming variable_set() but I am having trouble with the syntax. Could anyone lend a hand?

share|improve this question

2 Answers

If you want to set a variable with the URI returned from the query, you just execute code similar to the following one:

variable_set('variable name', $result->uri);

Replace "variable name" with the name you want to give to the Drupal variable, which is the same one you pass to variable_get().

share|improve this answer
In that way, the value name is always 'variable name', not the actual variable name ;) – Chris Burgess Feb 23 '12 at 21:27

Once you have your result, variable_set syntax is simply name, value:

variable_set('background_audio', 'meep.au');

Does that answer your question?

share|improve this answer
In that way, the value is always "meep.au" not the result from the query. – kiamlaluno Feb 22 '12 at 6:54

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.