Jump to content

Archived

This topic is now archived and is closed to further replies.

gerkintrigg

Splitting variables' names

Recommended Posts

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|format

There'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.

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.