Form is made from a function that prints out all rows that are awaiting approval;
function all_reviews(){
$query1= mysql_query("SELECT * FROM {$table} WHERE first != '' && disp_state= '0' && rejected != '1'");
if (!$query1) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($query1);
// printing table rows
while($row = mysql_fetch_array($query1))
{
//review action buttons
echo "<div class=\"rev_action\">";
echo "<input type=\"hidden\" name=\"".$row['id']."\">";
echo "<input type=\"submit\" name=\"accept\" value=\"Approve\" class=\"success rev_button\" onclick=\"document.getElementById('review_action').submit()\">";
echo "<input type=\"submit\" name=\"reject\" value=\"Reject\" class=\"error rev_button\" onclick=\"document.getElementById('review_action').submit()\">";
echo "</div>";
}
I’m guessing that the proper way is by printing out the row id in a hidden input. Problem is, there could be more than 1 row that print out at a time.
How do I select the exact row related to the approve or reject button?
html:
<form name="form" action="include/review_submit.php" id="review_action" method="post">
<?php all_reviews(); ?>
</form>
php (review_submit.php):
//database server connection
mysql_connect ("$servername","$dbusername","$dbpassword") or die(mysql_error());
//database connection
mysql_select_db("esd_db") or die(mysql_error());
//data feilds from review form
if($_POST['button'] == "Approve") {
//code to update given row with an approval status
}
//data feilds from review form
if($_POST['button'] == "Reject") {
//code to update given row with an rejection status
}
//insert values into table
mysql_query("UPDATE `reviews` ") or die(mysql_error());
Print "Success";
?>
You could always make each row a different form, and pass it to a dynamic URL, where the GetDATA would tell of which one you selected.
Or alternately, you could NOT use a form, and have each one link to a page. (Assume that the action page is action.php, and you have 100 rows. You could have action.php?row=1&ac=y, action.php?row=1&ac=n, etc)