?
Solved

update multiple records???????

Posted on 2003-03-03
6
Medium Priority
?
194 Views
Last Modified: 2006-11-17
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);
0
Comment
Question by:derksj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 8056326
Put your query in while loop

Harry
0
 

Author Comment

by:derksj
ID: 8056340
Sorry i am very new to php and databases

how should that query look like
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 8056378
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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 5

Expert Comment

by:harwantgrewal
ID: 8056383
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
 
LVL 8

Accepted Solution

by:
us111 earned 600 total points
ID: 8057433
<?
$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
 
LVL 8

Expert Comment

by:us111
ID: 9138038
very old question. thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question