Forum Moderators: open
curently I have following script for database update:
for($i=0; $i<$_POST['all']; $i++){
$q = "UPDATE ".TBL_RESULTS." SET time = '".strtotime($_POST['time'.$i])."', team1 = '".$_POST['team1'.$i]."', score1 = '".$_POST['score1'.$i]."', score2 = '".$_POST['score2'.$i]."', team2 = '".$_POST['team2'.$i]."', timestamp = $time WHERE id = '".$_POST['which'.$i]."'";
mysql_query($q);
} Is it possible to change only rows for which change ware made in form? I mean if I have 10 rows in edit script, but I made change only for one row, is it possible to change only that row? I need this because timestamp will be updated for all rows and that is not what i want. I select from that table against timestamp with limit 2, so I would like to select only two rows where changes ware made last.
for($i=0; $i<$_POST['all']; $i++){
$q = "UPDATE ".TBL_RESULTS." SET time = '".strtotime($_POST['time'.$i])."', team1 = '".$_POST['team1'.$i]."', score1 = '".$_POST['score1'.$i]."', score2 = '".$_POST['score2'.$i]."', team2 = '".$_POST['team2'.$i]."', timestamp = $time WHERE id = '".$_POST['which'.$i]."'";
mysql_query($q);
} Hi,
What you can do,
1. Define variable 'status'.$i in scripting page and set default value = 0
2. If there is any update then set it to 'status'.$i = 1.
3. In For loop check if $_POST['status'.$i] = 1 then only update the value :
Sol :
for($i=0; $i<$_POST['all']; $i++){
if($_POST['status'.$i]==1)
{
$q = "UPDATE ".TBL_RESULTS." SET time = '".strtotime($_POST['time'.$i])."', team1 = '".$_POST['team1'.$i]."', score1 = '".$_POST['score1'.$i]."', score2 = '".$_POST['score2'.$i]."', team2 = '".$_POST['team2'.$i]."', timestamp = $time WHERE id = '".$_POST['which'.$i]."'";
mysql_query($q);
}
} hope this will work.
[edited by: Discovery at 7:10 am (utc) on July 28, 2007]