non cambiare il sistema php... fai così
metti tutte le checkbox in un div o span con un unico id e poi cicli il contenuto dell' id
codice:
<script>
function SelectAll(State,ObjId)
{
var CheckList=document.getElementById(ObjId).getElementsByTagName('input');
for (var a=0;a < CheckList.length;a++)
{
if (CheckList[a].type == 'checkbox') CheckList[a].checked=State;
}
}
</script>
<input type="checkbox" onclick="SelectAll(this.checked,'chkbox')">seleziona tutti
<span id="chkbox">
<input name="libri[]" type="checkbox" value="<?=$row_rec_lista['ID']?>" >
<input name="libri[]" type="checkbox" value="<?=$row_rec_lista['ID']?>" >
<input name="libri[]" type="checkbox" value="<?=$row_rec_lista['ID']?>" >
<input name="libri[]" type="checkbox" value="<?=$row_rec_lista['ID']?>" >
<input name="libri[]" type="checkbox" value="<?=$row_rec_lista['ID']?>" >
<input name="libri[]" type="checkbox" value="<?=$row_rec_lista['ID']?>" >
</span>