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

  • Home
  • SEARCH
  • 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 9172947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:28:26+00:00 2026-06-17T16:28:26+00:00

I am trying to add the result of two DB_QUERY inside a function one

  • 0

I am trying to add the result of two DB_QUERY inside a function one after one by help of WHILE, but getting result one only one WHILE when I am downloading CSV, where I am printing the final variable. Here is the code –

    <?php

function getPaidScoutUsers($nid) {
  $csv_output = '';
  $all_paid_scouts_entry = db_query("SELECT * FROM {signup_event} WHERE event_nid = %d",$nid);
  while($paid_user = db_fetch_object($all_paid_scouts_entry)){
    $role_name     = 'Scout';
    $profile       = content_profile_load(scout_profile, $paid_user->attendee_uid);
    $firstname     = $profile->field_sfname[0]['value'];
    $lname         = $profile->field_last_name[0]['value'];
    $patrol        = get_term_name($profile->field_scout_patrol[0]['value']);
    $position      = get_term_name($profile->field_scout_rank[0]['value']);    
    $homephone     = "";
    $cellphone     = "";
    $email         = "";
    $paid_status   = 'Paid';
    $payment_date  = date_format_date($paid_user->created_date[0]['value'],$type = 'custom', $format = 'm/d/Y');
    $csv_output .= "\"".$role_name."\"".","."\"".$lname ."\"".","."\"".$firstname."\"".","."\"".$patrol."\"".","."\"".$position."\"".","."\"".$homephone."\"".",".$cellphone.",".$email.","."\"".$paid_status."\"".","."\"".$payment_date."\""."\r";    
  }
  return $csv_output;
}

function getUnpaidUsers($nid) {
    $csv_output = '';
    $all_unpaid_scout_list = db_query("SELECT * FROM users
                                     INNER JOIN users_roles ON users.uid = users_roles.uid
                                     WHERE users_roles.rid =7
                                     AND users.uid NOT IN (
                                     SELECT attendee_uid FROM signup_event WHERE event_nid = %d)
                                     ORDER BY name ASC",$nid);
    while($unpaid_user = db_fetch_object($all_unpaid_scout_list)){
      $role_name     = 'Scout';
      $profile       = content_profile_load(scout_profile, $unpaid_user->uid);
      $firstname     = $profile->field_sfname[0]['value'];
      $lname         = $profile->field_last_name[0]['value'];
      $patrol        = get_term_name($profile->field_scout_patrol[0]['value']);
      $position      = get_term_name($profile->field_scout_rank[0]['value']);   
      $homephone     = trim($profile->home_phone[0]['value']);
      $cellphone     = trim($profile->cell_phone[0]['value']);
      $email         = $profile->email_1;
      $paid_status   = 'Unpaid';
      $payment_date  = '';
      $csv_output .= "\"".$role_name."\"".","."\"".$lname ."\"".","."\"".$firstname."\"".","."\"".$patrol."\"".","."\"".$position."\"".","."\"".$homephone."\"".",".$cellphone.",".$email.","."\"".$paid_status."\"".","."\"".$payment_date."\""."\r";
    }
    return $csv_output;
}

function event_signup_download_detail($nid)
{ 
    //global $user;   
    module_load_include('inc', 'signup_event', 'event_signup_view');
    $csv_output = '';
    $csv_output .= "Role,Last name,First Name,Patrol,Position,Home phone,Cell Phone,Email,Payment Status,Payment Date\n";           
    $nid = 2001;

    // add the paid users to the csv 
    $csv_output .= getPaidScoutUsers($nid);

    // get unpaid users, add them to the csv
    //$csv_output .= getUnpaidUsers($nid);

    echo $csv_output;

    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment;   filename=\"Registration_Dues_Information.csv\"");
    print $csv_output;
    exit; 

}

Where I am wrong in this ? Can anybody help ?

  • 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-06-17T16:28:27+00:00Added an answer on June 17, 2026 at 4:28 pm

    Try splitting the functionality into seperate methods.

    function getPaidScoutUsers($nid) {
    
      $csv_output = '';
      $all_paid_scouts_entry = db_query("SELECT * FROM {signup_event} WHERE event_nid = %d",$nid);
      while($paid_user = db_fetch_object($all_paid_scouts_entry)){
        $role_name     = 'Scout';
        $profile       = content_profile_load(scout_profile, $paid_user->attendee_uid);
        $firstname     = $profile->field_sfname[0]['value'];
        $lname         = $profile->field_last_name[0]['value'];
        $patrol        = get_term_name($profile->field_scout_patrol[0]['value']);
        $position      = get_term_name($profile->field_scout_rank[0]['value']);
        $homephone     = trim($paid_user->home_phone);
        $cellphone     = trim($paid_user->cell_phone);
        $email         = $profile->email_1;
        $paid_status   = 'Paid';
        $payment_date  = date_format_date($paid_user->created_date[0]['value'],$type = 'custom', $format = 'm/d/Y');
        $csv_output .= "\"".$role_name."\"".","."\"".$lname ."\"".","."\"".$firstname."\"".","."\"".$patrol."\"".","."\"".$position."\"".","."\"".$homephone."\"".",".$cellphone.","."\"".$paid_status."\"".","."\"".$payment_date."\""."\r";    
      }
    
      return $csv_output;
    }
    
    function getUnpaidUsers($nid) {
        $csv_output = '';
        $all_unpaid_scout_list = db_query("SELECT * FROM users
                                         INNER JOIN users_roles ON users.uid = users_roles.uid
                                         WHERE users_roles.rid =7
                                         AND users.uid NOT IN (
                                         SELECT attendee_uid FROM signup_event WHERE event_nid = %d)
                                         ORDER BY name ASC",$nid);
        while($unpaid_user = db_fetch_object($all_unpaid_scout_list)){
          $role_name     = 'Scout';
          $profile       = content_profile_load(scout_profile, $unpaid_user->uid);
          $firstname     = $profile->field_sfname[0]['value'];
          $lname         = $profile->field_last_name[0]['value'];
          $patrol        = get_term_name($profile->field_scout_patrol[0]['value']);
          $position      = get_term_name($profile->field_scout_rank[0]['value']);   
          $homephone     = trim($profile->home_phone[0]['value']);
          $cellphone     = trim($profile->cell_phone[0]['value']);
          $email         = $profile->email_1;
          $paid_status   = 'Unpaid';
          $payment_date  = '';
          $csv_output .= "\"".$role_name."\"".","."\"".$lname ."\"".","."\"".$firstname."\"".","."\"".$patrol."\"".","."\"".$position."\"".","."\"".$homephone."\"".",".$cellphone.",".$email.","."\"".$paid_status."\"".","."\"".$payment_date."\""."\r";
        }
    
    
        return $csv_output;
    }
    
    function event_signup_download_detail($nid)
    { 
        global $user;   
        module_load_include('inc', 'signup_event', 'event_signup_view');
        $csv_output = '';
        $csv_output .= "Role,Last name,First Name,Patrol,Position,Home phone,Cell Phone,Email,Payment Status,Payment Date\n";        
    
        // add the paid users to the csv 
        $csv_output .= getPaidScoutUsers($nid);
    
        // get unpaid users, add them to the csv
        $csv_output .= getUnpaidUsers($nid);
    
        header("Content-type: application/vnd.ms-excel");
        header("Content-Disposition: attachment;   filename=\"Registration_Dues_Information.csv\"");
        print $csv_output;
        exit; 
    
    }
    

    note: i didn’t test this code

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

Sidebar

Related Questions

I'm trying to add two 4800x9600 matrices, but am running into difficulties... It's a
I am trying to get a simple renderscript function to take two numnbers, add
I am calling a function twice from two different functions, But for one of
I am trying to add two matrices using pthreads.Just a beginners program,but I am
I'm trying to add a property or two to a Django result object before
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a blank sample app for a rails tutorial to GitHub, but
I am trying to add/sub/multiply two complex numbers. Terminal said there is a SyntaxError
I am trying to configure a replica set with two nodes but when I
I'm trying to calculate the number of days between two days, but I'm running

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.