0

我需要将一个变量传递给另一个函数并在 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 无法识别......有什么问题?

4

1 回答 1

0

简单地?$pid该函数内部没有定义。

于 2013-09-23T03:29:10.277 回答