我需要将变量传递到另一个函数中,并在foreach之外传递
function eri_add_custom_user_profile_fields( $user ) {
$sql="SELECT `pid`,
max(case when `meta_key` = 'nome' then `meta_value` end) as nome ,
max(case when `meta_key` = 'pagina' then `meta_value` end) as pagina ,
max(case when `meta_key` = 'punti' then `meta_value` end) as punti ,
max(case when `meta_key` = 'cpc' then `meta_value` end ) as cpc
FROM wp_usermeta
GROUP BY `pid`
ORDER BY cpc DESC";
global $wpdb;
$usermeta = $wpdb->get_results($sql) or die(mysql_error());
foreach ($usermeta as $post) {
echo $post->pid; //i want update the generated user id
echo $post->nome;
echo $post->pagina;
echo $post->punti;
echo $post->cpc;
$result = $post->punti-$post->cpc;
echo $result;
<input type="hidden" name="ptotali" id="ptotali" value="<?php echo $result; ?>" class="regular-text" />
<input type="submit" name="updateuser" id="updateuser" value="update" class="regular- text" />
}
}
function eri_save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
// Update and Save Field
update_usermeta( $pid, 'ptotali', $_POST['ptotali'] );
}
add_action( 'show_user_profile', 'eri_add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'eri_add_custom_user_profile_fields' );
add_action( 'personal_options_update', 'eri_save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'eri_save_custom_user_profile_fields' );
使用相同的代码手动放置 PID,例如 3,它正确更新了 PID 编号 3,但无法识别变量$pid......怎么了?
简单地说?该函数中没有$pid
的定义。