update multiple records???????

How should i update these data
should i use an array or something and how does that work

$result = mysql_query("SELECT divisie.divisie,
tblcoordinatoren.naam,
tblcoordinatoren.ID,
tblcoordinatoren.afdeling,
tblcoordinatoren.telefoon
FROM tblcoordinatoren
INNER JOIN divisie ON (tblcoordinatoren.divisieID = divisie.divisieID) Order by divisie");



while ($myrow = mysql_fetch_array($result))
{



?>
<table border="0" width="100%"><tr>
<td width="25%" align="left">
<input type="text" name="ID"
VALUE="<?php echo $myrow "ID"]; ?>" size="25"></td>
<td width="25%" align="left">
<input type="text" name="naam"
VALUE="<?php echo $myrow["naam"]; ?>" size="25"></td>
<td width="25%" align="left">
<input type="text" name="afdeling"
VALUE="<?php echo $myrow["afdeling"]; ?>" size="25">
</td><td width="25%" align="left">
<input type="text" name="telefoon"
VALUE="<?php echo $myrow["telefoon"]; ?>" size="25">
</td>
}
echo "</td>\n";
echo "</tr>\n";


My updatequery looks like this but now he only updates the last record

$sql = "UPDATE tblcoordinatoren SET naam='$naam', afdeling='$afdeling', telefoon='$telef
oon', divisieID='$divisie' WHERE ID = '$ID'";
$result = mysql_Query($sql);
derksjAsked:
Who is Participating?
 
us111Connect With a Mentor Commented:
<?
$result = mysql_query("SELECT divisie.divisie,
tblcoordinatoren.naam,
tblcoordinatoren.ID,
tblcoordinatoren.afdeling,
tblcoordinatoren.telefoon
FROM tblcoordinatoren
INNER JOIN divisie ON (tblcoordinatoren.divisieID = divisie.divisieID) Order by divisie");



while ($myrow = mysql_fetch_array($result))
{
?>
<table border="0" width="100%">
     <tr>
     <td width="25%" align="left">
          <input type="text" name="ID[<?=$myrow "ID"]?>]" VALUE="<?php echo $myrow "ID"]; ?>" size="25">
     </td>
     <td width="25%" align="left">
          <input type="text" name="naam[<?=$myrow "ID"]?>]" VALUE="<?php echo $myrow["naam"]; ?>" size="25">
     </td>
     <td width="25%" align="left">
          <input type="text" name="afdeling[<?=$myrow "ID"]?>]" VALUE="<?php echo $myrow["afdeling"]; ?>" size="25">
     </td>
     <td width="25%" align="left">
          <input type="text" name="telefoon[<?=$myrow "ID"]?>]" VALUE="<?php echo $myrow["telefoon"]; ?>" size="25">
     </td>
     </tr>
</table>
<?     }     ?>


the file for updating
<?
     while (list($index, $value) = each($ID))
     {
          .........
          $sql = "UPDATE tblcoordinatoren SET naam='$naam[$value]', afdeling='$afdeling[$value]', telefoon='$telefoon[$value]', divisieID='$ID[$value]' WHERE ID = '$value'";
          $result = mysql_Query($sql);
          ............
     }
?>


get the idea!!
0
 
harwantgrewalCommented:
Put your query in while loop

Harry
0
 
derksjAuthor Commented:
Sorry i am very new to php and databases

how should that query look like
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
harwantgrewalCommented:
query is the same are you mentioned if its in while loop it updates each record or what you can do make a comma sperated value of is and so this query. This will update all the records.


 "UPDATE tblcoordinatoren SET naam='$naam', afdeling='$afdeling', telefoon='$telef
oon', divisieID='$divisie' WHERE ID in ($list)";
0
 
harwantgrewalCommented:
Sorry query will be look like this in your while loop

UPDATE tblcoordinatoren SET naam='$naam', afdeling='$afdeling', telefoon='$telef
oon', divisieID='$divisie' WHERE ID = ".$myrow ["ID"];

Harry
0
 
us111Commented:
very old question. thanks
0
All Courses

From novice to tech pro — start learning today.