We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsDrupalDrupal Security

How to Generate a Unique Serial Number per User per Node Type

Brazil VPS
Germany Cloud Servers
OpenVZ VPS
cPanel KVM
Linux KVM Hosting
KVM VPS
Ubuntu VPS
USA VPS
Windows Cloud Server
Linux Cloud Server

The idea of this unique serial number generator is having a field in each node which displays a number on which a node is based according to the author and content type. This feature hardly could be implemented by using Drupal basic functions. Therefore, you might need to implement custom made functions achieve such features.

Follow These Steps to Generate a Unique Serial Number per User per Node Type

By using correct functions the code is not very difficult and long. Let’s look at the example of the following code block:

1
2
3
4
5
<?php
$before = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE uid = %d AND type = '%s' AND nid < %d", $node->uid, $node->type, $node->nid));
$username = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $node->uid));
$node_field[0]['value'] = t('This is %user\'s %type #%number', array('%user' => $username, '%type' => node_get_types('name', $node), '%number' => $before + 1));
?>

After implementing such lines of code in our Drupal installation you should get unique serial numbers generated for each node based on the author and content type. For example, if the first author will publish his first page, it should show a field stating it is a first page based on the first author. The same feature will be used for all the rest of the authors and their pages.

Germany Cloud Servers
KVM VPS
OpenVZ VPS
Linux KVM Hosting
Brazil VPS
cPanel KVM
Ubuntu VPS
Linux Cloud Server
Windows Cloud Server
USA VPS
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Other (195)

Popular Keywords