I have a table and it contains more than one column, and one of columns is to check/select all checkboxes in my table rows, actually I can select one or multiple checkboxes if I want from the checkboxes that are in the rows.
I have searched and found this result: multiple checkboxes with php in table but it's not helpful, and I couldn't understand it completely.
What I want from my code to do is: When I select one or multiple checkboxes, then when I click on (Publish) button -the code for the button is down below within the page code- the page should receive the selected values from the checkboxes and send them to the same page (article?do=pub&articleid='.$fileid)
This is the code:
<?php
$Title = 'Manage Approved Articles';
include 'init.php';
$AdminName = $_SESSION['username'];
// Check if user is the Admin or not
$stmt = $con->prepare('SELECT Username FROM users WHERE Username = ? AND isAdmin = 1');
$stmt->execute(array($AdminName));
$count = $stmt->rowCount();
if($count > 0) { } else {
header('Location: ../index');
exit();
}
?>
<section class="Cust-container">
<?php
$do = isset($_GET['do']) ? $_GET['do'] : 'article';
if($do == 'article') { echo
'<h2 class="heading">Manage Articles</h2>'; ?>
<!-- Manage Articles Page -->
<table class="admin-article-table">
<thead>
<tr>
<th width="41%">Article Title</th>
<th width="18%">Category</th>
<th width="10%">By</th>
<th width="10%">Publish
<input style="height: 20px; width: 20px;margin-left: 7px"
type="checkbox"
id="checkAll">
</th>
<th width="21%">Options</th>
</tr>
</thead>
<tbody>
<?php
// retrieving data from db
$stmt = $con->prepare('SELECT * FROM uploads WHERE Approved = 1');
$stmt->execute();
$rows = $stmt->fetchAll();
if(empty($rows)) { echo
'<tr>
<td class="empty" colspan="5">There\'re No Approved Articles</td>
</tr>';
} else {
foreach ($rows as $row) {
$fileid = $row['FileID'];
$filedir = $row['FileDirectory'];
$catID = $row['CatID'];
$F_name = array_shift(explode('.', $row['FileName']));
$full_fname = $row['FileName'];
$uploaderId = $row['User_ID']; echo
'<tr>
<td>' . $row['ArticleTitle'] . '</td>';?>
<?php
$stmt = $con->prepare('SELECT * FROM cats WHERE ID = ?');
$stmt->execute(array($catID));
$rows = $stmt->fetchAll();
if(empty($rows)) {
echo "<td class='empty'>No Declared Category</td>";
} else {
foreach ($rows as $row) {
$category = $row['Category'];
} echo '
<td>'.$category.'</td>
';
}
echo '<td>';?>
<?php
$stmt = $con->prepare('SELECT FullName FROM users WHERE UserID = ?');
$stmt->execute(array($uploaderId));
$rows = $stmt->fetchAll();
foreach ($rows as $row) {
echo $row['FullName'];
} echo '
</td>
<td>
<input type="checkbox" name="Publ[]"
value="'.$fileid.'" class="chk" required>
</td>
<td>';?>
<?php echo '
<a class="option-del" style="margin-left: 12%;float:left" href="?do=delete&fileid='.$fileid.'&fullName='.$full_fname.' "onclick="return ConfirmContin(this);">Delete</a>
<a class="option" style="float:left;margin-right: -30px" href="?do=unapprove&fileid='.$fileid.'&filename='.$F_name.'&fullnm='.$full_fname.'" onclick="return ConfirmContin(this);">Unapprove</a>
<br><br><br>
<form method="post" action="?do=updateCat&fileid='.$fileid.'">
<select name="cats">';
$stmt = $con->prepare('SELECT * FROM cats');
$stmt->execute();
$rows = $stmt->fetchAll();
if(empty($rows)) {
echo "<option>-- No Categories Found --</option>";
} else {
echo "<option value='0' Title='delete the article from its chosen category'>Make as Uncategorized</option>";
foreach ($rows as $row) {
$catid = $row['ID'];
$catname = $row['Category'];
echo '<option value='.$catid.'>'.$catname.'</option>';
}
} echo '</select><input type="submit" style="width:130px;height:40px;border-color:#777;background-color:#444;color:#FFF" value="Update"></form>
</td>
</tr>
';
}
}
?>
</tbody>
<tr><td colspan="3"></td>
<td>
<input type="submit" value="Publish" name="publish"
style="width:130px;height:40px;border-color:#090B64;
background-color:#475590;color:#FFF">
</td>
<td></td></tr>
</table>
</section>
<?php
} elseif ($do == 'pub') {
// Some Code for handling the sent values (sent by clicking on Publish button) from the selected checkboxes that exists in the table rows
} else {
header('Location: ../index');
exit();
} ?>
<?php
include $tpl . 'footer.php';
?>
This is a screen shot of the table:
Table for checking multiple checkboxes
I am a beginner and I don't know a lot about php and handling requests (get and post). if I didn't clarify my question enough please ask me in which point I didn't, so you can fully understand my problem and help me solving it hopefully.
So much of thanks.