尝试根据所选ID更新行

时间:2019-11-09 05:15:22

标签: php wordpress

在这里,我想根据所选ID更新用户表上的成员状态。在我的foreach语句中,有一个激活按钮,用于更新。现在不再更新所选行,而只是更新第一行。这意味着它将使用第一个ID而不是所选ID。我该如何获取正确的ID?

function check_view() {
 global $wpdb;


 $output .= '<table>
  <tr style="color: #fff; background: #08a873">
    <th> &nbsp; Account ID</th>
    <th> &nbsp; Name</th>
    <th>Phone</th>
    <th>Email</th>
    <th>Referer ID</th>
    <th> Activate Member</th>
  </tr>';
 $results = $wpdb->get_results("select * from $wpdb->users WHERE memberStatus = 'Not Active'"); 
 $current_date = date('Y-m-d H:i:s');

 foreach( $results as $user_data) {


        $startTimeStamp = strtotime($user_data->deposit_date);
        $endTimeStamp = strtotime($current_date);

        $timeDiff = abs($endTimeStamp - $startTimeStamp);

        $numberDays = $timeDiff/86400;  // 86400 seconds in one day

        // and you might want to convert to integer
        $numberDays = intval($numberDays);

       $roi = $user_data->amount * 2;  
       $amount_growth = $roi - $user_data->amount;

 $output .= "<tr>
    <td> $user_data->ID</td>
    <td> $user_data->user_nicename</td>
    <td> $user_data->Phone</td>
    <td> $user_data->user_email</td>
    <td> $user_data->refID</td>
    <td> <form method='post'> <input type='submit' name='submit' value='Activate' /> </form> </td>
  </tr>";


 if($_POST['submit']) {

    $todate = date('Y-m-d H:i:s');   

    //Update Member Status
    $status = "Active";
    $where = array('ID' => $user_data->ID);
        $subs = array('user_registered' =>  $todate, 'memberStatus'=> $status);
        $table_name  = $wpdb->prefix."users";

       $actMember = $wpdb->update($table_name, $subs, $where);


     if($actMember) {
       header("Refresh:0");
       exit;
          } else {
       echo 'not';
       }
 }

 }
 $output .= '</table>';

 return $output;
}

0 个答案:

没有答案