At 14:29 15-1-03, you wrote:
That would work good and is shorter than what i did (and accidently mailed to myself in stead of to this list):> not with the same data > You can put your data and the primary keys in arrays and exec a loop but the data[0] must be the data for the id[0], data[1] must be the data for id[1] etc.The loop should be something like this: for (int $i=0; $i<=total_records_select_returned -1; $i++) update table set field1='$data[$i]' where id=$id[$i]; I 'm not sure for the syntax but the idea is correct.
You split the record ID and value in two form elements while I lump the fieldname with the recordID into the form element name.
The way i understand the question is, you have several records (or rows) in one table that you want to edit on the same page.I have table with six records in it. I can use "while" to display them all, but in form. Is there any way I can edit all six records, and update them all with one submit.
One of the many ways to do it:So to make this do something like
When writing the form, number the fieldnames with the ID's of the items. Separate name and ID with a clear character like '__'
<input type="text" name="field__531">
<input type="text" name="field__532">
<input type="text" name="field__533">
1. make a query to select the items, select the values you want to show as well as the record's ID field, from now I will call that $recordID.
Echo a <form method="POST" action="whatever.php"> tag
2. Loop through the query result with your favourite loop structure and in the loop echo each record somehow like this:
echo ' <input type="text" name="'.fieldname__$recordID.'" value='.$recordfield.'>';
With fieldname 'fieldname':In the receiving page, split the name again. Then build a query for every record.
while (list ($key, $val) = each ($_POST)) //walk through all form results, key is form_element_name
//and value is value.
{if (! strpos($key,'fieldname')===false) //only with variables starting with the fieldname
{ $keybits=explode('__',$key);$recordID=$keybits[1]; //split the recordID out of the name of the variable
$query="UPDATE mytable SET fieldname='.$value.' WHERE recordID=$recordID";
mysql_query($query) or die('Problem updating data );
}
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php