You are here

function recipe_ingredient_id_from_name in Recipe 5

Same name and namespace in other branches
  1. 6 recipe.module \recipe_ingredient_id_from_name()
  2. 7.2 recipe.module \recipe_ingredient_id_from_name()
  3. 7 recipe.module \recipe_ingredient_id_from_name()

Converts a recipe ingredient name to and ID

2 calls to recipe_ingredient_id_from_name()
recipe_import_from_46 in ./recipe.module
recipe_save_ingredients in ./recipe.module
Saves the changed ingredients of a recipe node to the database (by comparing the old and new ingredients first)

File

./recipe.module, line 566
recipe.module - share recipes for drupal 5.x

Code

function recipe_ingredient_id_from_name($name) {
  static $cache;
  if (!$cache[$name]) {
    $ingredient_id = db_result(db_query("SELECT id FROM {recipe_ingredient} WHERE LOWER(name)='%s'", trim(strtolower($name))));
    if (!$ingredient_id) {
      global $active_db;
      $node_link = db_result(db_query("SELECT nid FROM {node} WHERE title = '%s'", $name));
      db_query("INSERT INTO {recipe_ingredient} (name, link) VALUES ('%s', '%s')", $name, $node_link);
      $ingredient_id = db_result(db_query("SELECT id FROM {recipe_ingredient} WHERE LOWER(name)='%s'", trim(strtolower($name))));
    }
    $cache[$name] = $ingredient_id;
  }
  return $cache[$name];
}