Jump to content

Splitting variables' names


gerkintrigg

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.