0

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?

<?php 
global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM $wpdb->users" );
?>
<form method="post">
<table>
  <tr>
    <th>ID</th>
    <th>Nombre</th>
    <th>Nobility</th>
    <th>Select Nobility</th>
    <th>Submit</th>
  </tr>
<?php 
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>
      <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>
       </select>
      </td> 
      <td><button type='submit' name='submit'>Submit</button></td>";
    }
  }
  echo "</tr>"; 
}?>
</form>
<?php
if(isset($_POST["submit"])){
   $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.