Your code seems to work for a menu change where the uid, I want to be the uid of the member who is navigating the site.
I will also have similar links on members' user pages, profile pages, etc....so for these, the uid wouldn't change, it would always be the uid of that node's author.
I made the following change and it seems to work:
<?php global $user; $node_type = 'story'; if (db_num_rows(db_query("SELECT * FROM {node} WHERE type='%s' AND uid=%d", $node_type, $node->uid))) { print(t("View Story")); } else { print(t("Create Story")); } ?>
----- Original Message ----- From: "Jason Flatt" drupal@oadaeh.net To: support@drupal.org Sent: Friday, October 05, 2007 3:34 PM Subject: Re: [support] db query to find out if member has node of type X
On Friday 05 October 2007 03:02:22 Neil: esl-lounge.com wrote:
How would I find out if User A had authored a node of type X?
I have a link "View Story" that I would like to be "Create Story" if that member hasn't yet created that node type.
Is that a complicated db query to do?
Probably something like this would do it:
global $user; $node_type = 'story'; if (db_num_rows(db_query("SELECT * FROM {node} WHERE type='%s' AND uid=%d", $node_type, $user->uid))) { print(t("View story")); } else { print(t("Create story")); }
Note: that is totally untested code and is likely to contain one or more errors.
-- Jason Flatt http://www.oadaeh.net/ Father of Six: http://www.flattfamily.com/ (Joseph, 14; Cramer, 12; Travis, 10; Angela; Harry, 7; and William, 12:04 am, 12-29-2005) Linux User: http://www.xubuntu.org/ Drupal Fanatic: http://drupal.org/ -- [ Drupal support list | http://lists.drupal.org/ ]