PHP/MYSQL Bulk Actions

mezangath

New Member
Hi there,

I have a database for managing points of members.
The database is constructed by

|id (primary, unique, AI) | name | rank | points | class
|123 |name1|Officer|20 |Warrior

The list consists of about 30 different id's for each member added to the list.

What i want to do is to create bulk actions. So i can mark several/all members and add a set of points to existing points.

The form i use is:
HTML:
<form action="update_bulk.php" method="post" />
<input type="text" name="ud_points" value="Points"/>
<input type="submit" value="Quick Edit" />

And for each member they get:
HTML:
<input type='checkbox' name='ud_id' value='$id' />

Now, this form is being sent to update_bulk.php witch look like this:
PHP:
$ud_id=$_POST['ud_id'];
$ud_points=$_POST['ud_points'];

require_once('mysql.php');

$query="UPDATE members SET points='$ud_points' WHERE id='$ud_id'";
mysql_query($query);

Now, i'm a real noob when it comes to PHP/Mysql, so i could really use some help with this PHP/Mysql action.

What i want is for the script to update the points value of all id's sent to it.
Not only paste in the same number but to add the value, so if i write 20 in ud_points i want it to add those to existing value.

Anyone who has a clue? :)
 

anthwinter

New Member
Hey

What you could do is retrieve the value from the table, then store it in a variable. then you can use PHP to add the to variables together and then submit this back into the table

use something like:

$getpoints="SELECT points FROM members WHERE id='$ud_id'";
mysql_query($getpoints);

while ($row = mysql_fetch_array($getpoints)) {
$currentpoints = $row['points'];
}

$newpoints = $ud_points + $currentpoints;

$query="UPDATE members SET points='$newpoints' WHERE id='$ud_id'";
mysql_query($query);
 
author of Zend Technologies’ PHP 101 series for
PHP beginners (http://www.zend.com/php5/abs/), and has extensive experience
deploying PHP and MySQL in a variety of different environments (including
corporate intranets, high-traffic Internet web sites, and mission-critical thin client
applications).
 
Top