# \[Help\] Updating Multiple Rows in MySQL Table at Once

**URL:** <https://forum.kirupa.com/t/help-updating-multiple-rows-in-mysql-table-at-once/330343>\
**Category:** programming\
**Created:** [January 5, 2013, 9:35am UTC](https://forum.kirupa.com/t/help-updating-multiple-rows-in-mysql-table-at-once/330343 "2013-01-05T09:35:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![40Unregistered](https://avatars.discourse-cdn.com/v4/letter/4/87869e/32.png) [@40Unregistered](https://forum.kirupa.com/u/40Unregistered)\
**Post date:** [January 5, 2013, 9:35am UTC](https://forum.kirupa.com/t/help-updating-multiple-rows-in-mysql-table-at-once/330343/1 "2013-01-05T09:35:08Z")

</div>

I want to update 160 rows in MySQL table at once.  
This approach works but it seems not optimize enough and sometimes it failed. It runs 160 queries, isn’t it? How to optimize this script?

FYI: pdfdones are data from Flash, not html form.

```php
$done = array($_POST['pdfdone1'],$_POST['pdfdone2'],$_POST['pdfdone3'] ... $_POST['pdfdone160'])

$idx = array(1,2,3 ... 160)

$count = count($idx);

for($i=0;$i<$count;$i++){
 $sql1="UPDATE $table SET pdfdone='$done[$i]' WHERE id='$idx[$i]'";
 $result1=mysql_query($sql1);
}

```

Please help.
