gerkintrigg Posted August 5, 2006 Share Posted August 5, 2006 Hiya!I'm almost there with a script, but I'm having trouble with splitting a variable name into numbers and letters.I'm using "explode" to chop up posted variables like this:[code]foreach($_POST as $k=>$v) { if (($k !="Submit") &&($v!="Submit")) { $explode=explode('|', $k, 2));[/code]Each field that is being posted is automatically generated from a database and is called something like this: 14|formatThere's also 1|weight_min etc. The point is that I want to chop up the keys into the number and the word so that I can use the number as an id field in the database, to update the relating field.I hope that makes sense.I've used explode so-far, but I'm not sure how to execute the SQL query, or how to access the first or second part of the explode array. (Is it even an array!?)Please help. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted August 5, 2006 Share Posted August 5, 2006 Try:$array = explode('|', $row['k'], 2);$k = $array[0];$number = $array[1]; Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted August 5, 2006 Author Share Posted August 5, 2006 it's cool... I got it:[code]if ($_REQUEST['change']=='y'){ foreach($_POST as $k=>$v) { if (($k !="Submit") &&($v!="Submit")) { $explode=explode('|', $k, 2); $q = "UPDATE `postage` SET `".$explode[1]."` = '".$v."' WHERE `id` =".$explode[0]." LIMIT 1 ;"; $rs = mysql_query($q) or die("Problem with query: $q<br>" . mysql_error()); } }}[/code]I did it all by myself too... how proud I am!! Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted August 5, 2006 Author Share Posted August 5, 2006 oh, sorry hostfreak, didn't see your reply there. thanks for that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.