[support] db query to find out if member has node of type X

Neil: esl-lounge.com neil at esl-lounge.com
Fri Oct 5 14:08:25 UTC 2007


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 at oadaeh.net>
To: <support at 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/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20071005/21e0f141/attachment.htm 


More information about the support mailing list