Forum Moderators: coopster
$query = "SELECT * FROM info WHERE class = 'Math'";
$data = mysqli_query($db, $query);
$row = mysqli_fetch_array($data);
$time = 5;
// Begin and IF statement to update the rows
if ($row['time'] != $row['mtime']) {
$updatetime = $query = "UPDATE info set time=time+$time, WHERE class = 'Math'";
} // Close If
// You've **already** selected all records where class='MATH'.
// your update inside the while loop should only
// update the CURRENT record.
$time = 5;
while ($row = mysqli_fetch_array($data)) {
if ($row['time'] != $row['mtime']) {
$this_id=$row[0]; // first in $row array, use $row['id'] if you want
$query = "UPDATE info set time=time+$time where id=$this_id";
// execute the update here
}
}
$query = "select * from table";
// execute
while ($row [etc]) {
$query = "some other query";
}
$query = "UPDATE info set time=time+$time where id=$this_id";
$query = "UPDATE info set time=time+$time where id=$this_id limit 1";
if any 1 of the values doesn't match it will update all of the values.
update table set field1=field1+$field1, field2=field2+$field1, field3=field3+$field3, field4=field4+$field4 where ((field1 != mfield1) or (field2 != mfield2) or (field3 != mfield3) or (field4 != mfield4)) and class='Math';
if any 1 of the values doesn't match it will update all of the values.
$fields = Array(
'health' => 1,
'energy' => 1,
'stamina' => 1,
'honor' => 1
);
//
foreach ($fields as $key=>$value) {
$mfield = 'm' . $key; // make "mhealth" etc
$query = "update information set $field=$field+$value where $field=$mfield and class='Math';
// execute query here
}
$increment=1;
$fields = Array('health','energy','stamina','honor');
//
foreach ($fields as $fld) {
$mfield = 'm' . $fld;
$query = "update information set $field=$field+$increment where $field=$mfield and class='Math';
// execute query here
}
I figured you would need the while loop still to only impact one row at a time
<?
require_once('connectvars.php');
// Connect to the database and establish values for replenishing Zaltens
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
//
$increment=1;
$fields = Array('health','energy','stamina','honor');
//
foreach ($fields as $fld) {
$mfield = 'm' . $fld;
$query = "update information set $field=$field+$increment where $field!=$mfield and class='Math';
$data = mysqli_query($dbc, $query) or die("cannot execute: ". mysql_error());
// Still troubles? Echo this, copy and paste into phpadmin
// echo "$query<br>\n";
}
mysqli_close($dbc);
?>