1

I created a triggered rule. The action will 'fill a field'. To get the value for this field I need to get a value saved in sql database. Then I check to set the value using php and create this code:

$result = mysql_query("SELECT field_codigo_value FROM content_type_inmuebles_en_venta SORT BY field_codigo_value LIMIT 1");
$value = mysql_fetch_array($result);

return array(
  0 => array('value' => $value )
); 

But I get this error message:

warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/drupal6multilingual/sites/all/modules/rules/rules/modules/php.rules.inc(107) : eval()'d code on line 2.

2
  • Check $result before passing it to mysql_fetch_array. It may be false if query fails Aug 22, 2011 at 17:07
  • Why aren't you using Drupal's database API ?
    – tostinni
    Aug 22, 2011 at 17:30

1 Answer 1

1

First off, you should be using the drupal SQL coding conventions:

db_query instead of mysql_query
db_fetch_array instead of mysql_fetch_array

I would structure the query like so:

$query = "SELECT field_codigo_value
          FROM content_type_inmuebles_en_venta 
          SORT BY field_codigo_value 
          LIMIT 1";

$result = db_query($query);

return $result; 

You should know that triggered rules allows you to pull a value out of the database without writing a custom query. We need a bit more context as to how this node is related to your triggered rule, but I would guess that you can load the node that you just created or load a referenced node to the node that you just created and then use the available tokens to fill in the CCK field that you need filled in.

1
  • You are right, drupal conventions is the right way to do it. Thanks
    – chefnelone
    Aug 22, 2011 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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