Jump to content

Update multiple rows with same variable


drewb29693

Recommended Posts

I am runnig the fetch array and everything is working great.  What i am having trouble with is when i go to update a row on another page, it is only grabbing the last $POST_['goal_id'] because i don't know how to store ever one that passes through that while loop.  if i could just assign each post that it runs through in the the loop to a variable that would be great, but i am new at this so i don't know how.  Any help would be great.

 

 

<?php 

$line = 1;

while($row1 = mysql_fetch_array($result)){ ?>
     
     <tr>
       <td width="124" height="40" align="right" valign="top" scope="col"><?php echo "Goal ". $line++ . ":";?><span
         class="style1">__</span>     </td>
       
<td width="408" height="40" valign="top" scope="col"><?php echo $row1['goal']; ?></td>
        
       <input type="hidden" readonly="readonly" name="goal_id" id="goal_id" value="<?php echo $row1['goal_id'];?>"      
          size="12"/>  
     <?php } ?>

Link to comment
Share on other sites

The problem is that you are giving the input fields the same name (and it is not an array). Therefore only one value is passed. Just change the field name to be an array using square brakets, like so:

 
<input type="hidden" readonly="readonly" name="goal_id[]" id="goal_id" value="<?php echo $row1['goal_id'];?>" size="12"/>

 

Then in your receiving page, you can create one UPDATE query using the IN control:

$idList = implode(',', $_GET['goal_id']);  //Assumes numeric field
$query = "UPDATE table SET filed='value' WHERE goal_id IN ({$idList})";

 

Also, you need to give every element a unique ID, you cannot use the same ID twice.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.