Community Documentation

db_result

5 database.mysql.inc db_result($result, $row = 0)
5 database.pgsql.inc db_result($result, $row = 0)
5 database.mysqli.inc db_result($result, $row = 0)
6 database.mysql.inc db_result($result)
6 database.pgsql.inc db_result($result)
6 database.mysqli.inc db_result($result)

Return an individual result field from the previous query.

Only use this function if exactly one field is being selected; otherwise, use db_fetch_object() or db_fetch_array().

Parameters

$result: A database query result resource, as returned from db_query().

Return value

The resulting field or FALSE.

Related topics

▾ 120 functions call db_result()

actions_function_lookup in includes/actions.inc
Given an md5 hash of a function name, return the function name.
aggregator_block in modules/aggregator/aggregator.module
Implementation of hook_block().
block_add_block_form_validate in modules/block/block.admin.inc
block_admin_configure_validate in modules/block/block.admin.inc
block_flush_caches in modules/block/block.module
Implementation of hook_flush_caches().
book_block in modules/book/book.module
Implementation of hook_block().
book_update_6000 in modules/book/book.install
Drupal 5.x to 6.x update.
comment_multiple_delete_confirm in modules/comment/comment.admin.inc
List the selected comments and verify that the admin really wants to delete them.
comment_new_page_count in modules/comment/comment.module
Calculate page number for first new comment.
comment_nodeapi in modules/comment/comment.module
Implementation of hook_nodeapi().
comment_num_all in modules/comment/comment.module
Get comment count for a node.
comment_num_new in modules/comment/comment.module
Get number of new comments for current user and specified node.
comment_num_replies in modules/comment/comment.module
Get replies count for a comment.
comment_publish_action in modules/comment/comment.module
Action to publish a comment.
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
comment_unpublish_action in modules/comment/comment.module
Action to unpublish a comment.
comment_validate in modules/comment/comment.module
Validate comment data.
dblog_cron in modules/dblog/dblog.module
Implementation of hook_cron().
db_check_setup in includes/database.pgsql.inc
Verify if the database is set up correctly.
db_column_exists in includes/database.pgsql.inc
Check if a column exists in the given table.
db_last_insert_id in includes/database.mysql-common.inc
Returns the last insert id.
db_last_insert_id in includes/database.pgsql.inc
Returns the last insert id. This function is thread safe.
db_table_exists in includes/database.pgsql.inc
Check if a table exists.
db_version in includes/database.pgsql.inc
Returns the version of the database server currently in use.
do_search in modules/search/search.module
Do a query on the full-text search index for a word or words.
drupal_get_filename in includes/bootstrap.inc
Returns and optionally sets the filename for a system item (module, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists.
drupal_is_denied in includes/bootstrap.inc
Perform an access check for a given mask and rule type. Rules are usually created via admin/user/rules page.
drupal_lookup_path in includes/path.inc
Given an alias, return its Drupal system URL if one exists. Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE.
file_space_used in includes/file.inc
Determine total disk space used by a single user or the whole filesystem.
filter_admin_format_form_submit in modules/filter/filter.admin.inc
Process filter format form submissions.
filter_format_allowcache in modules/filter/filter.module
Check if text in a certain input format is allowed to be cached.
filter_list_format in modules/filter/filter.module
Retrieve a list of filters for a certain format.
flood_is_allowed in includes/common.inc
Check if the current visitor (hostname/IP) is allowed to proceed with the specified event.
forum_nodeapi in modules/forum/forum.module
Implementation of hook_nodeapi().
hook_file_download in developer/hooks/core.php
Control access to private file downloads and specify HTTP headers.
hook_form_alter in developer/hooks/core.php
Perform alterations before a form is rendered.
hook_search in developer/hooks/core.php
Define a custom search routine.
hook_update_N in developer/hooks/install.php
Perform a single update.
install_verify_drupal in ./install.php
Verify if Drupal is installed.
locale_languages_predefined_form_validate in includes/locale.inc
Validate the language addition form.
locale_translate_edit_form_submit in includes/locale.inc
Process string editing form submissions.
locale_update_6000 in modules/locale/locale.install
{locales_meta} table became {languages}.
locale_update_6005 in modules/locale/locale.install
Change language setting variable of content types.
locale_update_6006 in modules/locale/locale.install
Neutralize unsafe language names in the database.
menu_delete_menu_confirm in modules/menu/menu.admin.inc
Build a confirm form for deletion of a custom menu.
menu_delete_menu_confirm_submit in modules/menu/menu.admin.inc
Delete a custom menu and all items in it.
menu_edit_menu_submit in modules/menu/menu.admin.inc
Submit function for adding or editing a custom menu.
menu_edit_menu_validate in modules/menu/menu.admin.inc
Validates the human and machine-readable names when adding or editing a menu.
menu_enable in modules/menu/menu.module
Implementation of hook_enable()
menu_link_children_relative_depth in includes/menu.inc
Find the depth of an item's children relative to its depth.
menu_link_save in includes/menu.inc
Save a menu link.
menu_nodeapi in modules/menu/menu.module
Implementation of hook_nodeapi().
node_access in modules/node/node.module
Determine whether the current user may perform the given operation on the specified node.
node_access_view_all_nodes in modules/node/node.module
Determine whether the user has a global viewing grant for all nodes.
node_admin_nodes in modules/node/node.admin.inc
Form builder: Builds the node administration overview.
node_assign_owner_action in modules/node/node.module
Implementation of a configurable Drupal action. Assigns ownership of a node to a user.
node_assign_owner_action_form in modules/node/node.module
node_assign_owner_action_submit in modules/node/node.module
node_assign_owner_action_validate in modules/node/node.module
node_comment_mode in modules/node/node.module
Retrieve the comment mode for the given node ID (none, read, or read/write).
node_multiple_delete_confirm in modules/node/node.admin.inc
node_revision_delete_confirm_submit in modules/node/node.pages.inc
node_search in modules/node/node.module
Implementation of hook_search().
node_type_delete_confirm in modules/node/content_types.inc
Menu callback; delete a single content type.
node_type_save in modules/node/node.module
Saves a node type to the database.
node_update_index in modules/node/node.module
Implementation of hook_update_index().
openid_association in modules/openid/openid.module
Attempt to create a shared secret with the OpenID Provider.
openid_user_add_validate in modules/openid/openid.pages.inc
openid_user_delete_form in modules/openid/openid.pages.inc
Present a confirmation form to delete the specified OpenID identity from the system.
openid_verify_assertion_nonce in modules/openid/openid.module
Verify that the nonce has not been used in earlier assertions from the same OpenID provider.
pager_query in includes/pager.inc
Perform a paged database query.
path_admin_form_validate in modules/path/path.admin.inc
Verify that a new URL alias is valid
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.
path_form_alter in modules/path/path.module
Implementation of hook_form_alter().
path_nodeapi in modules/path/path.module
Implementation of hook_nodeapi().
php_install in modules/php/php.install
Implementation of hook_install().
ping_cron in modules/ping/ping.module
Implementation of hook_cron().
poll_block in modules/poll/poll.module
Implementation of hook_block().
profile_autocomplete in modules/profile/profile.pages.inc
Callback to allow autocomplete of profile text fields.
profile_category_access in modules/profile/profile.module
Menu item access callback - check if a user has access to a profile category.
profile_field_form_validate in modules/profile/profile.admin.inc
Validate profile_field_form submissions.
search_update_totals in modules/search/search.module
This function is called on shutdown to ensure that search_total is always up to date (even if cron times out or otherwise fails).
sess_count in includes/session.inc
Counts how many users have sessions. Can count either anonymous sessions or authenticated sessions.
system_admin_theme_submit in modules/system/system.module
Process admin theme form submissions.
system_initialize_theme_blocks in modules/system/system.module
Assign an initial, default set of blocks for a theme.
system_install in modules/system/system.install
Implementation of hook_install().
system_region_list in modules/system/system.module
Get a list of available regions from a specified theme.
system_update_6000 in modules/system/system.install
Remove auto_increment from {boxes} to allow adding custom blocks with visibility settings.
system_update_6009 in modules/system/system.install
The PHP filter is now a separate module.
system_update_6018 in modules/system/system.install
Add HTML corrector to HTML formats or replace the old module if it was in use.
system_update_6019 in modules/system/system.install
Reconcile small differences in the previous, manually created mysql and pgsql schemas so they are the same and can be represented by a single schema structure.
system_update_6021 in modules/system/system.install
Migrate the menu items from the old menu system to the new menu_links table.
system_update_6036 in modules/system/system.install
Change the search schema and indexing.
system_update_6041 in modules/system/system.install
Change forum vocabulary not to be required by default and set the weight of the forum.module 1 higher than the taxonomy.module.
translation_remove_from_set in modules/translation/translation.module
Remove a node from its translation set (if any) and update the set accordingly.
trigger_assign_form_submit in modules/trigger/trigger.admin.inc
Submit function for trigger_assign_form().
trigger_assign_form_validate in modules/trigger/trigger.admin.inc
Validation function for trigger_assign_form().
trigger_menu in modules/trigger/trigger.module
Implementation of hook_menu().
upload_delete_revision in modules/upload/upload.module
upload_save in modules/upload/upload.module
upload_total_space_used in modules/upload/upload.module
Determine how much disk space is occupied by uploaded files.
user_admin_role_validate in modules/user/user.admin.inc
user_block in modules/user/user.module
Implementation of hook_block().
user_multiple_delete_confirm in modules/user/user.module
user_multiple_role_edit in modules/user/user.module
Callback function for admin mass adding/deleting a user role.
user_save in modules/user/user.module
Save changes to a user account or add a new user.
_aggregator_has_categories in modules/aggregator/aggregator.module
Find out whether there are any aggregator categories.
_batch_page in includes/batch.inc
State-based dispatcher for the batch processing page.
_blogapi_space_used in modules/blogapi/blogapi.module
_blog_post_exists in modules/blog/blog.module
Helper function to determine if a user has blog posts already.
_book_update_outline in modules/book/book.module
Common helper function to handles additions and updates to the book outline.
_comment_update_node_statistics in modules/comment/comment.module
Updates the comment statistics for a given node. This should be called any time a comment is added, deleted, or updated.
_forum_new in modules/forum/forum.module
Finds the first unread node for a given forum.
_forum_topics_unread in modules/forum/forum.module
Calculate the number of nodes the user has not yet read and are newer than NODE_NEW_LIMIT.
_locale_import_one_string_db in includes/locale.inc
Import one string into the database.
_menu_find_router_path in includes/menu.inc
Find the router path which will serve this path.
_menu_update_parental_status in includes/menu.inc
Check and update the has_children status for the parent of a link.
_node_access_rebuild_batch_operation in modules/node/node.module
Batch operation for node_access_rebuild_batch.
_node_revision_access in modules/node/node.module
_user_edit_validate in modules/user/user.module

File

includes/database.pgsql.inc, line 206
Database interface code for PostgreSQL database servers.

Code

<?php
function db_result($result) {
  if ($result && pg_num_rows($result) > 0) {
    $array = pg_fetch_row($result);
    return $array[0];
  }
  return FALSE;
}
?>

Comments

Count rows

Count rows in a table using db_result:

<?php
  $countrows
= db_result(db_query("SELECT COUNT(*) FROM {my_table}"));
?>

db_result removed from Drupal 7

Drupal6:

$val = db_result(db_query({...}))

may be rewritten in Drupal7 as
$val = db_query({...})->fetchField();

Count rows in a table

Drupal 6:

You can get the num_rows value from query ResultSet. Here is the Example:

$resultSet = db_query($query);

print_r($resultSet->num_rows);

Correct but the num_rows

Correct but the num_rows property may only be used if mysqli connection is active.

Resets resource ID

Does this function make the $result variable unusable? I have a query that checks if a row exists, if not then it should print an error. If there is a row, carry on with the rest of the query and return

if ($salesdesk) { 
  $result = db_query("SELECT nid FROM {content_type_salesdesk} WHERE nid = %d AND field_status_value = 2", $salesdesk);
   //drupal_set_message(db_result($result));
  if (db_result($result) == NULL) {
   drupal_set_message('Could not send products to Salesdesk. Please check the the Salesdesk is registered with the Quote Engine');
  }
 


} else {
  $result = db_query("SELECT nid FROM {content_type_salesdesk} WHERE field_status_value = 2");
}



  while ($row = db_fetch_array($result)) {
  
   $node = node_load($row['nid']);
  
   $title = $node->title;
   $domain = $node->field_domain[0]['value'];
   $api_key = $node->field_salesdesk_key[0]['value'];
  
   $update = wuwo_salesdesk_services_pushproduct($title, $api_key, $domain);
  
   drupal_set_message($update);
  }
return;

Now if I give the query a saledesk that doesn't return a row then I get the error message. If I give it one that does exists, it doesn't do anything.

If I put the db_result into a drupal_set_message before the conditional then it tells kicks out the error message (as if it doesn't exist), when the row definitely does exist. Which indicates that the mysql resource id is being reset or set to false.

The rest of the script works without this conditional.

Login or register to post comments