I am getting the users via $wpdb, then I display the values id,name and mg_nobility in a table that has a dropdown menu to select the nobility and a submit button. how can I get the id of the row that correspond to the clicked submit button so I can update the mg_nobility in the database, and how will the query look? Should I use $wpdb insert?

global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
<form method="post">
    <th>Select Nobility</th>
foreach ($results as $key ) {
  echo "<tr>";
  foreach ($key as $row=>$value ) {

    if ($row == "ID" ) {
      echo "<td>$value</td>";
    }elseif ($row == "display_name") {
      echo "<td>$value</td>";
    }elseif ($row == "mg_nobility") {
      echo "<td>$value</td>
       <select name='nobility_value'>
        <option value='nobilityOne'>nobility One</option>
        <option value='nobilityTwo'>nobility Two</option>
        <option value='nobilityThree'>nobility Three</option>
        <option value='nobilityFour'>nobility Four</option>
      <td><button type='submit' name='submit'>Submit</button></td>";
  echo "</tr>"; 
   $nobility = $_POST['nobility_value'];
  # wordpress query....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.