Re: [PHP] How to post unknown amount of data ?
The best way of doing this is to name the fields catid[] The [] means that they are inserted into an array in the order they appear on the page, so on the page with deals results you just have to cycle through the array. As a side point, there is no way of telling what has been modified and what is not (well without comparing the variables to the db again).. so it is usually quicker just to update the whole.lot. HTH, Tom - Original Message - From: vz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, August 08, 2001 12:00 PM Subject: [PHP] How to post unknown amount of data ? Hello all, I'm having a trouble. I'm programming an CMS for one pc company. So in example i'm doing a pc category catalog admin. They can add/delete/modify theese category's. But also they want one feature: they want to edit all category's in one form. So i made a form that displays all category's in input type=text so they can edit, but the problem is that i dunno how many there will be category's and how to organize data passing to script. User submits form with all changes, and my script needs to get all theese category's with id's and changed names. Ok how it looks in script: Function display_all() { Print form action='category.php' method='post' name='editcat' INPUT TYPE=hidden NAME='admin_editall' VALUE='1'; $result=mysql_query(SELECT cat_id, cat_name, cat_show FROM cat GROUP BY cat_id ASC); While ($row=mysql_fetch_array($result)) { $cat_id=$row[cat_id]; $cat_name=$row[cat_name]; $cat_show=$row[cat_show]; Print tr class=tb1tdinput type='text' name='cat_id' size='2' maxlength='4' value='$cat_id' disabled/td\n; Print tdinput type='text' name='cat_name$cat_id' size='50' maxlength='50' value='$cat_name'/td tdinput type='checkbox' name='cat_status'; if ($cat_show==Y) {Print checked;} Print /td/tr\n; } } // ^^^ this form post all data into same file category.php file://and function add_all_db() must get all data. Function add_all_db(){ ? // here i must add theese changes to db // i know how to add to db, but dunno // how to get forms passed data. } PHP Version 4.0.4pl1 MySQL Version 3.22.30 Thank u for your help. Vilius Zigmantas aka vz [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] How to post unknown amount of data ?
You can enumerate the form vars for example if you have an unkown amount of comments for($i=0;$isizeof($comments);$i++) { echo input type=text name=commentid$i; } etc Bolke (sorry I'm not going to look at your code, better split HTML creation and data(-retrieval)) Bolke -Oorspronkelijk bericht- Van: vz [mailto:[EMAIL PROTECTED]] Verzonden: Wednesday, August 08, 2001 1:00 PM Aan: [EMAIL PROTECTED] Onderwerp: [PHP] How to post unknown amount of data ? Hello all, I'm having a trouble. I'm programming an CMS for one pc company. So in example i'm doing a pc category catalog admin. They can add/delete/modify theese category's. But also they want one feature: they want to edit all category's in one form. So i made a form that displays all category's in input type=text so they can edit, but the problem is that i dunno how many there will be category's and how to organize data passing to script. User submits form with all changes, and my script needs to get all theese category's with id's and changed names. Ok how it looks in script: Function display_all() { Print form action='category.php' method='post' name='editcat' INPUT TYPE=hidden NAME='admin_editall' VALUE='1'; $result=mysql_query(SELECT cat_id, cat_name, cat_show FROM cat GROUP BY cat_id ASC); While ($row=mysql_fetch_array($result)) { $cat_id=$row[cat_id]; $cat_name=$row[cat_name]; $cat_show=$row[cat_show]; Print tr class=tb1tdinput type='text' name='cat_id' size='2' maxlength='4' value='$cat_id' disabled/td\n; Print tdinput type='text' name='cat_name$cat_id' size='50' maxlength='50' value='$cat_name'/td tdinput type='checkbox' name='cat_status'; if ($cat_show==Y) {Print checked;} Print /td/tr\n; } } // ^^^ this form post all data into same file category.php //and function add_all_db() must get all data. Function add_all_db(){ ? // here i must add theese changes to db // i know how to add to db, but dunno // how to get forms passed data. } PHP Version 4.0.4pl1 MySQL Version 3.22.30 Thank u for your help. Vilius Zigmantas aka vz [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] How to post unknown amount of data ?
forgot something to enumerate them in your script use something like for ($i=0;$isizeof($comments);$i++) { $cmt = $HTTP_FORM_VARS[commentid . $i]; } Bolke -Oorspronkelijk bericht- Van: Bruin, Bolke de [mailto:[EMAIL PROTECTED]] Verzonden: Wednesday, August 08, 2001 1:20 PM Aan: 'vz'; [EMAIL PROTECTED] Onderwerp: RE: [PHP] How to post unknown amount of data ? You can enumerate the form vars for example if you have an unkown amount of comments for($i=0;$isizeof($comments);$i++) { echo input type=text name=commentid$i; } etc Bolke (sorry I'm not going to look at your code, better split HTML creation and data(-retrieval)) Bolke -Oorspronkelijk bericht- Van: vz [mailto:[EMAIL PROTECTED]] Verzonden: Wednesday, August 08, 2001 1:00 PM Aan: [EMAIL PROTECTED] Onderwerp: [PHP] How to post unknown amount of data ? Hello all, I'm having a trouble. I'm programming an CMS for one pc company. So in example i'm doing a pc category catalog admin. They can add/delete/modify theese category's. But also they want one feature: they want to edit all category's in one form. So i made a form that displays all category's in input type=text so they can edit, but the problem is that i dunno how many there will be category's and how to organize data passing to script. User submits form with all changes, and my script needs to get all theese category's with id's and changed names. Ok how it looks in script: Function display_all() { Print form action='category.php' method='post' name='editcat' INPUT TYPE=hidden NAME='admin_editall' VALUE='1'; $result=mysql_query(SELECT cat_id, cat_name, cat_show FROM cat GROUP BY cat_id ASC); While ($row=mysql_fetch_array($result)) { $cat_id=$row[cat_id]; $cat_name=$row[cat_name]; $cat_show=$row[cat_show]; Print tr class=tb1tdinput type='text' name='cat_id' size='2' maxlength='4' value='$cat_id' disabled/td\n; Print tdinput type='text' name='cat_name$cat_id' size='50' maxlength='50' value='$cat_name'/td tdinput type='checkbox' name='cat_status'; if ($cat_show==Y) {Print checked;} Print /td/tr\n; } } // ^^^ this form post all data into same file category.php //and function add_all_db() must get all data. Function add_all_db(){ ? // here i must add theese changes to db // i know how to add to db, but dunno // how to get forms passed data. } PHP Version 4.0.4pl1 MySQL Version 3.22.30 Thank u for your help. Vilius Zigmantas aka vz [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]