drewb29693 Posted March 10, 2010 Share Posted March 10, 2010 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/194789-update-multiple-rows-with-same-variable/ Share on other sites More sharing options...
Psycho Posted March 10, 2010 Share Posted March 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194789-update-multiple-rows-with-same-variable/#findComment-1024303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.