Update database with multiple checkbox states
Posted: Thu Aug 27, 2009 1:03 pm
Hi,
I have searched high and low to try and find a solution to my problem but I am unable to find exactly what I need. I have followed a few ideas but to no avail. So any help would be appreciated.
I have a database of content. Of this content some are featured on the main page of the site. I need to be able to check and uncheck boxes to decide what content is featured on the main page.
So I have queried the database and looped through all the content in there and put that in a table.
I can determine the current 'featured' content and preset the checkbox next to it either on or off.
What I can't do is send the information of changes to the checkboxes, to the database.
Scenario:
Page 1 - Featured
Page 2 - Featured
Page 3 - Not Featured
Page 4 - Featured
I want to uncheck Page 1, check Page 3 and update the database with a value of 1 or 0 then reload the data on the current page.
Here is some code.
Any help would be appreciated.
I have searched high and low to try and find a solution to my problem but I am unable to find exactly what I need. I have followed a few ideas but to no avail. So any help would be appreciated.
I have a database of content. Of this content some are featured on the main page of the site. I need to be able to check and uncheck boxes to decide what content is featured on the main page.
So I have queried the database and looped through all the content in there and put that in a table.
I can determine the current 'featured' content and preset the checkbox next to it either on or off.
What I can't do is send the information of changes to the checkboxes, to the database.
Scenario:
Page 1 - Featured
Page 2 - Featured
Page 3 - Not Featured
Page 4 - Featured
I want to uncheck Page 1, check Page 3 and update the database with a value of 1 or 0 then reload the data on the current page.
Here is some code.
Code: Select all
<form name="checkFeatured" method="post" action="adminCHECKED.php" />
<table class="zebra">
<tr>
<td class="width"><strong>Page Name</strong></td>
<td class="adjacent"><strong>Description</strong></td>
<td class="adjacent"></td>
<td class="adjacent"><strong>Date Modified</strong></td>
<td class="adjacent"><strong>Featured</strong></td>
</tr>
<?php
$result = mysql_query("SELECT * FROM pages ORDER BY slug");
while($row = mysql_fetch_array($result))
{
if ($row['featured'] == 1){
$checked = 'checked';
}
else {
$checked = '';
}
echo '<tr>
<td class="width">' . $row['title'] . '</td>
<td class="adjacent">' . $row['description'] . '</td>
<td class="edit"><a href="template.php?page=' . $row['slug'] . '&edit=1">Edit</a></td>
<td class="adjacent">' . $row['modified'] . '</td>
<td class="adjacent"><input type="checkbox" name="featured"' . $checked . '/>
</tr>';
}
?>
</table>
<div id="adminSave">
<input align="right" type="submit" name="featured_submit" value="Save" />
</div>
</form>