I have a PHP script where a person can update multiple items from one page. Now part of what that script does is takes multiple items but only those that have their checkboxes check. now while this is good and an effective way of doing multiple updates at 1 time it does seem kind of tedious to have to check alll those boxes if there is more than 50 results, which another part of the site does have. Is their anyway way for the check box to be automatically check when when a change has occurred in a textfield, dropdown menu, or even another checkbox?
Here is a sample of what I am using. Thanks in advance
Here is a sample of what I am using. Thanks in advance
PHP Code:
<?php
mysql_connect('localhost', 'user', 'pass');
mysql_select_db('test');
if(isset($_POST['submit'])) {
$updatedrows = 0;
foreach($_POST['changed'] as $id) {
$name = $_POST["name_$id"];
$quantity = $_POST["quantity_$id"];
$query = "UPDATE products SET name='$name', "
. "quantity='$quantity' WHERE id=$id";
mysql_query($query);
$updatedrows += mysql_affected_rows();
}
}
//grab data from database
$result = mysql_query('SELECT * FROM products ORDER BY id');
$products = array();
while($row = mysql_fetch_assoc($result)) {
$products[$row['id']] = array('name'=>$row['name'],
'quantity'=>$row['quantity']);
}
mysql_close();
?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title>Update Inventory</title>
</head>
<body>
<?php if(isset($updatedrows))
echo $updatedrows . " row(s) updated.<br /><br />\n";
?>
<form method="post"
action="<?php echo $_SERVER['PHP_SELF']; ?>"
name="updateform">
<table border="1">
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Update Row</th>
</tr>
<?php foreach($products as $id=>$product) { ?>
<tr>
<td><input type="text" size="25"
value="<?php echo $product['name']; ?>"
name="name_<?php echo $id; ?>" />
</td>
<td><input type="text" size="4"
value="<?php echo $product['quantity']; ?>"
name="quantity_<?php echo $id; ?>" />
</td>
<td><input type="checkbox"
value="<?php echo $id; ?>"
name="changed[]" />
</td>
</tr>
<?php } //end for loop ?>
</table>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?
Comment