gpt4 book ai didi

php - 函数内有两个 WHILE - 没有执行一个

转载 作者:行者123 更新时间:2023-11-30 23:23:39 24 4
gpt4 key购买 nike

我试图在 WHILE 的帮助下将两个 DB_QUERY 的结果一个接一个地添加到一个函数中,但是当我下载 CSV 时,我只得到一个 WHILE 结果,我正在打印最终变量。这是代码-

    <?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;

}

我哪里错了?有人可以帮忙吗?

最佳答案

尝试将功能拆分为单独的方法。

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;

}

注意:我没有测试这段代码

关于php - 函数内有两个 WHILE - 没有执行一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14352880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com