note 23036 added to ref.array

From: Date: Sun, 07 Jul 2002 19:19:52 +0000
Subject: note 23036 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-32714@lists.php.net to get a copy of this message
i have a problem and i'm hoping somebody could help me with it. basically i have a form with multiple text input boxes. the number of these increases...so the next <tr> would have username2,comment2,date2,time2.And the nextone 3...and so on. So when the data is posted it s saved as an array in $HTTP_POST_VARS. what i would need to do is somehow create a function that would foreach usernameX commentX dateX timeX do a mysql query: UPDATE comments SET username='$username', comment='$comment', date='$date', time='$time' where id=$key" . This way all of the fields would be updated with one post.oh yeah $id is the X at the end of username,comment,date and time. The only way i knew how to do it(since i know almost zero php. 1) do a listing of the $HTTP_POST_VARS. 2)remove all instances of username comment date and time from the keys.and there for get a listing 1 1 1 1 2 2 2 2 ... then just check if the key wasn't allready done and if it wasn't extract the username+key comment+key date+key and time+key values of of $HTTP_POST_VARS, and update the database. Basically i got everything out of the array so i can just get the X values and call the array again. Seems sort of stupid and a waste of time. I'm 100% sure there is an easier way of doing it.With foreach or smth.But everything i tried failed =). anyone have any ideas what to do? here is the so called code(well only the part that i think can be done another way: and yes the crap actually works: this is the part of the code that basically does all the garbage i wrote above: while (list($key, $value) = each ($HTTP_POST_VARS)) { $search = "/comment/"; $replacement = ""; $key = preg_replace($search, $replacement, $key); $search = "/username/"; $replacement = ""; $key = preg_replace($search, $replacement, $key); $search = "/date/"; $replacement = ""; $key = preg_replace($search, $replacement, $key); $search = "/time/"; $replacement = ""; $key = preg_replace($search, $replacement, $key); if($key!=$prev_key) { if($key != "function" AND $key != "show") { global $HTTP_POST_VARS; $username = "username"; $username .= $key; $comment = "comment"; $comment .= $key; $date = "date"; $date .= $key; $time = "time"; $time .= $key; $username = $HTTP_POST_VARS["$username"]; $comment = $HTTP_POST_VARS["$comment"]; $date = $HTTP_POST_VARS["$date"]; $time = $HTTP_POST_VARS["$time"]; $query = ("UPDATE comments SET username='$username', comment='$comment', date='$date', time='$time' where id=$key"); $result = MYSQL_QUERY($query); } } $prev_key = $key; } MYSQL_CLOSE(); does anybody have an example of a code that can edit multiple rows and columns at once?...like phpmyadmin. -- http://www.php.net/manual/en/ref.array.php http://master.php.net/manage/user-notes.php?action=edit+23036 http://master.php.net/manage/user-notes.php?action=delete+23036 http://master.php.net/manage/user-notes.php?action=reject+23036

« previous php.notes (#32714) next »