hi frds...
in my hiden textbox.i have following values...
robert|true|true|false|arun|true|false|true|anu|true|true|false|
i want to splits in to token and insert in mysql table in following manner
namefield writefiled readfield speakfield
robert true true false
arun true false true
anu true true false
thanks in advance...
problem insert values into table using tokenizer..
Moderator: General Moderators
-
chennaibala
- Forum Newbie
- Posts: 6
- Joined: Thu Sep 10, 2009 1:51 am
-
amargharat
- Forum Commoner
- Posts: 82
- Joined: Wed Sep 16, 2009 2:43 am
- Location: Mumbai, India
- Contact:
Re: problem insert values into table using tokenizer..
You can't split with this kind of pattern
robert|true|true|false|arun|true|false|true|anu|true|true|false
Instead of above, use following pattern in your hidden field.
robert;true,true,false|arun;true,false,true|anu;true,true,false
using above pattern, we can split easily
here is the code
robert|true|true|false|arun|true|false|true|anu|true|true|false
Instead of above, use following pattern in your hidden field.
robert;true,true,false|arun;true,false,true|anu;true,true,false
using above pattern, we can split easily
here is the code
Code: Select all
$pattern = "robert;true,true,false|arun;true,false,true|anu;true,true,false";
$expPattern = explode("|", $pattern); // after spliting in this manner, you'll get each user and his/her properties.
//loop it to store each namefield and his/ her properties
foreach ($expPattern as $param)
{
$expParam = explode(";", $param);
$namefield = $expParam[0];
$properties = $expParam[1];
//split $properties to get each property
$expProperties = explode(",", $properties);
$writefield = $expProperties[0];
$readfield = $expProperties[1];
$speakfield = $expProperties[2];
$sql = "INSERT INTO table(namefield, writefield, readfield, speakfield) VALUES('{$namefield}', '{$writefield}', '{$readfield}', '{$speakfield}')";
mysql_query($sql);
}