Forum Moderators: coopster
I had set up a table like this.
Id
Name
Win
Draw
Lost
Points
I need a page from where I can update all records at the same time. I can update one by one, can show the data, etc etc, but have no idea on how to update or delete multiple records via one single file.
T.I.A
as coopster asked originally, what exactly are you having trouble with?
What have you tried so far?
Do you want to update each row with a different value or put the same value in each row?
updating all rows can be very messy
Multiple deletes are easy
delete from tablename where id in ();
between the parentheses you put the list of ids seperated by a comma
The idea is to have and "ranking" position of about 15 teams of a legue.
So I need to update once a week all the results.
So $id $name will be always the same.
Win, lost, draw will be update for each team.
something like this:
-----------------------------------------------------
Id ¦ $name ¦win ¦ draw ¦ lost ¦ points
1 team1 1 0 0 5
2 team2 0 1 0 1
3 team3 0 0 1 0
So I can update the fields of all the teams in one single page and then click update and....PRESTO!
As I said before I have no problem, doing this one by one, and even making a page to show all this data as a form, but can't make the UPDATE thing works
any idea?
When it is posted the array can be looped through and each update query can be issued.
should work
well that explains it, hehe ;)
ok, seriously, try this for an example
you could create your form something like so though you would have to select data first, I just faked an array
<?
// you should populate this from your ids selected from your db
$idarr = array(1,5,7,24,55,76);
?>
<form method="post" action="loopupdate.php">
<?
$counter = 0;
foreach ($idarr as $nextid) {
echo '<p>name: <input type="text" name="name',$counter,"\">\n";
echo '<br>wins: <input type="text" name="win',$counter,"\">\n";
echo '<br>draws: <input type="text" name="draw',$counter,"\">\n";
echo '<br>losses: <input type="text" name="lost',$counter,"\">\n";
echo '<br>points: <input type="text" name="points',$counter,"\">\n"
echo "<input type=\"hidden\" name=\"id",$counter,"\" value=\"",$nextid,"\">\n\n";
$counter++;
}
?>
<p><input type="submit" value="update them all">
</form>
then create a file called loopupdate.php and put it in the same directory
<?
$counter = 0;
while (isset($_POST['name' . $counter])) {
echo "<p>update tablename set name='" . $_POST['name' . $counter] . "', win='" . $_POST['win' . $counter] . "', draw='" . $_POST['draw' . $counter] . "', lost='" . $_POST['lost' . $counter] . "', points='" . $_POST['points' . $counter] . "' where id=",$_POST['id' . $counter] . "\n";
$counter++;
}
?>
that's about it