Skip to content

Instantly share code, notes, and snippets.

@codehakase
Last active April 27, 2017 18:45
Show Gist options
  • Save codehakase/97e7f360b873a92275bf0aa65544bb6a to your computer and use it in GitHub Desktop.
Save codehakase/97e7f360b873a92275bf0aa65544bb6a to your computer and use it in GitHub Desktop.
<?php
/**say the students are pulled from a database table via a while loop (or what you're using)
it may look like this:
*/
?>
<?php while ($row = $yourTable->fetchObject()): ?>
<tr>
<td>$row->studentName</td>
the rest of the pull
...
</tr>
Now you can add a new table data to hold the button, a link preferably:
<td><a href="" class="someBtnClass">Promote</a>
you'll need to pass the student by their id via a get request
<td><a href="yourscript.php?student=<?= $row->id;?>"> promote </a>
note you're still in the loop so you can access the
since the id is being grabbed, the next thing is to run the query
<?php
// this code will be above the loop (best practice)
if (isset($_GET['student'])) {
$studentId = (int)$_GET['student']; // you can run extra checks here for empty data
// query
$promoteQuery = $dbDriver->query("UPDATE students SET class = '$theDataForTheClass' WHERE id = '$studentId'");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment