Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:32:47+00:00 2026-05-15T16:32:47+00:00

I am writing module which allows to quick add users only by providing First

  • 0

I am writing module which allows to quick add users only by providing First and Lastname (without emial address or user name). Those users are ‘ghost’ like, just for a temporary uses.
Before adding user module needs to check if user with the same first name and last name already exists in system to avoid creating multiple ghost users with the same personal names.
In other words – I need a sql query to filter users by last AND first name.
As till now I was able to produce such a query:

$sql = "SELECT DISTINCT u.uid AS uid FROM users u INNER JOIN profile_values pv ON u.uid = pv.uid INNER JOIN profile_fields pf ON pv.fid = pf.fid "
                ."WHERE pf.fid = 2 AND pv.value = '%s'";
            $uid = db_fetch_object(db_query("$sql", $ln))->uid;

This query is not good enought as it finds user only by matching lastname. I am not sql expert but I have no idea how to join tables to narrow results so firstname AND lastname are matched:
Something like this

WHERE pf.fid = 2 AND pv.value = 'LASTNAME' AND pf.fid = 1 AND pv.value = 'FIRSTNAME';

In my profile_fields table I have:
fid = 2 -> lastname
fid = 1 -> firstname

And last WHERE clause will not work. I hope those who are familiar with user – profile tables relationship in Drupal system knows what I am asking for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:32:48+00:00Added an answer on May 15, 2026 at 4:32 pm

    you need to join twice with different aliases. Something like:

    $sql = "SELECT DISTINCT u.uid AS uid FROM {users} u 
    INNER JOIN {profile_values} pv ON u.uid = pv.uid 
    INNER JOIN {profile_fields} pf ON pv.fid = pf.fid
    INNER JOIN {profile_values} pv2 ON u.uid = pv2.uid 
    INNER JOIN {profile_fields} pf2 ON pv2.fid = pf2.fid
    WHERE pf.fid = 2 
    AND pv.value = '%s'
    AND pf2.fid = 1 
    AND pv2.value = '%s'";
    
     $uid = db_fetch_object(db_query("$sql", array($ln, $fn)))->uid;
    

    Also with drupal you should put {} around table names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a add-on module which is integrated with an existing PHP application;
I'm writing a module which serializes others and I've got everything working only I'm
I'm writing a module which exports an interface similar to send and recv .
I'm writing an Account module which should take care of everything about accounts: registration,
I am writing a kernel module which forms its own packet at ip level
I am writing a python module which checks several media and document formats whether
I am writing a kernel module in which i have 3 source files and
I'm writing a Python-module which should provide an easy OOP interface to low-level GUI
I am writing a small module which will have several different aspects to it,
first, sorry about my english, i still learning. I writing Python module for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.