View Full Version : Updating Multiple records
langed31
01 Jun 2007, 09:33 AM
Here is my situation we have a helpdesk database and I am currently updating our support web site that uses the data in this database. I have a column called Tech and we sometimes will assign calls as unassigned until a specific tech takes them. What I would like to do is have a page that displays all calls marked as unassigned and be able to assign multiple calls at once to a tech. Here is how I was thinking of doing this, by having code that displays each record, then inserting a check box by each record and have one drop down list at the top of the page that lists each tech. When a check box is checked and a tech is selected the submit would update that record. I know how to diplay the records, but what I can't figure out is how to associate each checkbox with each different record when the number of records displayed changes based on the data. Thanks for your help.
bjk2007
18 Jul 2007, 06:48 PM
Here's a snippet of code for doing it.
<table>
<tr>
<td> </td>
<th>Title</th>
<th>Description</th>
<th>Status</th>
</tr>
<?php
$result = mysql_query("SELECT ID, title, description, status FROM tasks");
while ($row = mysql_fetch_assoc($result))
echo <<<HTML
<tr>
<td><input type="checkbox" name="job_{$row['ID']}" /></td>
<td>{$row['title']}</td>
<td>{$row['description']}</td>
<td>{$row['status']}</td>
</tr>
HTML;
?>
</table>
As you can see, all you have to do is give the checkbox a guaranteed unique name. Then, when the user submits the form you just need to filter the $_POST array for indexes that start with 'job_'. I'm pretty sure you can handle the rest. Any questions let me know.
FYI the mysql_ set of functions probably should be replaced with the mysqli_ counterparts if possible for better forward compatibility. I'm just not familiar with the mysqli version since I've been using frameworks.
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.