I need to first find out if a certain value X exists in a certain column in a certain table. Ideally, I just want a binary value returned, so I can proceed with other stuff, depending on whether or not X exists. I've reduced it to one line of Drupal code:
$value_exists = db_result(db_query("SELECT IF (%d in (SELECT id FROM {some_table}), 1, 0)", $value));It works! But it still seems pretty convoluted. Anyone know if there's a more elegant way to test if a value exists?
UPDATE: I posted this on the Drupal forums.
FURTHER UPDATE: There is a function called db_num_rows, but a) it seems to be PG-SQL only, b) you need to feed it the result id from your SELECT query anyway, so it doesn't really save you a step, and c) it seems that it's being phased out of Drupal 6.