Update multiple rows in a single query?

6 posts by 3 authors in: Forums > CMS Builder
Last Post: April 21, 2014   (RSS)

By nmsinc - April 12, 2014

I need to update multiple rows with a single query and having some problems - see code below:


<?php //location header - update 'claims_submission' page = auto_assign.php

if (@$_REQUEST['save']) {
 for($i=0;$i<$count;$i++){
 $sql1="UPDATE 'claims_submission' SET independent_dispatcher='$independent_dispatcher[$i]', independent_adjuster='$independent_adjuster[$i]' WHERE idd='$id[$i]'";
 $result1=mysql_query($sql1);
 }
 }
?>

<!-- PHP Form -->
<form action="auto_assign.php?" method="post">
<?php $id = ""; ?>
    <?php foreach ($claims_submissionRecords as $record): ?>             
    <?php $id[]=$record['num']; ?>

    
    
<td align="center" height="35" bgcolor="<?php echo $bgColor ?>"><font face="Verdana" size="3">
<!-- Select A Independent Dispatcher -->
  <select id="inddispatcher_drop" idd="independent_dispatcher "name="independent_dispatcher[]"> 
        <?php foreach ($independentAdjusterDispatcherDistanceToRecords as $distance => $users): ?>
          <?php foreach ($users as $user): ?>
            <?php if ($user['user_type'] == "Dispatcher" AND !$user['disabled']): ?>
              <option value = "<?php echo $user['num'];?>"><?php echo $user['fullname'];?> - <?php echo $distance != "Distance NA" ? $distance." mi" : 'Distance NA'; ?></option>
            <?php endif; ?>
          <?php endforeach ?>
        <?php endforeach ?>
        <?php foreach ($independentAdjusterDispatcherDistanceToRecords as $distance => $users): ?>
          <?php foreach ($users as $user): ?>
            <?php if (($user['user_type'] == "Dispatcher/Adjuster" OR $user['user_type'] == "Dispatcher/Processor" OR $user['user_type'] == "Dispatcher/Processor/Adjuster") AND !$user['disabled']): ?>
              <option value = "<?php echo $user['num'];?>"><?php echo $user['fullname'];?> - <?php echo $distance != "Distance NA" ? $distance." mi" : 'Distance NA'; ?></option>
            <?php endif; ?>
          <?php endforeach ?>
        <?php endforeach ?>
     </select>
<!-- //Select A Independent Dispatcher -->

<?php endforeach ?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  </table>
  <p>&nbsp;</p>
  <p>
      <br/>
  <input class="auto-style3" type="submit" name="submit" value="Assign Dispatchers, Adjusters & Processors &gt;&gt;" /><span class="auto-style3">
  </span>
    </td>
   </tr>
  </table>




I have only listed the primary code above that I feel I'm having problems with as the entire coded page would be to lengthy for viewers to search through. I feel it is within the '$i", '$id" or 'idd' sets and I can't seem to get a handle on it

Even though rows are present and changes have been made, nothing is updated upon submit and I receive no errors - any ideas on what I'm doing wrong?

Thanks - nmsinc

nmsinc

By Chris - April 14, 2014

Hi nmsinc,

Where are $count, $independent_dispatcher, and $id set? Can you please post the complete PHP source code for your page?

All the best,
Chris

Hi nmsinc,

I've looks as if you're mysql update statement is calling variables that don't exist. I can't see where the following variables are set:

  • $independent_dispatcher
  • $independent_adjuster

Do you know where these are being set? What should they contain?

It also looks as if the $ide variable is being set after the MySQL update statement is called.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By nmsinc - April 15, 2014

Hi Greg,

I highlighted in blue the variables that you could not find in the previous post - they are set by a select command and listed by the distance mapping routine just prior to the selections.

As far as the $ide variable, it looks as if it is set prior to the update command and not after it as I have a if (@$_REQUEST['save']) {} function that manages this in the header!

Any help would be much appreciated!

Thanks - nmsinc

nmsinc

By nmsinc - April 21, 2014

Hi Chris,

Got it work with your idea!

Thanks - nmsinc

nmsinc