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. Link to comment https://forums.phpfreaks.com/topic/16621-splitting-variables-names/ 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]; Link to comment https://forums.phpfreaks.com/topic/16621-splitting-variables-names/#findComment-69677 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!! Link to comment https://forums.phpfreaks.com/topic/16621-splitting-variables-names/#findComment-69679 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. Link to comment https://forums.phpfreaks.com/topic/16621-splitting-variables-names/#findComment-69680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.