I have a textarea that is populated with values. On submit button, I’m saving the value of textarea in a table in separate rows using this code:
echo "<center><textarea name='resulta' id='result' style='height:200px; width:350px' readonly=readonly></textarea></center>";
echo "<form><center><input type=submit name=subs value='Submit'></center></form>";
$val=$_POST['resulta'];
if (isset($_POST['subs']))
{
$lines = explode("\n", $val);
foreach ($lines as $line)
{
mysql_query("insert into postflight (sample_lang) values ('$line')") or die(mysql_error());
}
If I have inputted the following in the textarea:
Tokyo - London -> 10:00:00
London - Tokyo -> 11:00:00
The postflight table will have these data respectively,
sfno || bltime || sample_lang
00001 || 00:00:00 || Tokyo - London -> 10:00:00
00002 || 00:00:00 || London - Tokyo -> 11:00:00
But, what I want to do is, add to sample_lang column ‘Tokyo – London’ then add to bltime column ’10:00:00′. The data in the postflight should look like this:
sfno || bltime || sample_lang
00001 || 10:00:00 || Tokyo - London
00002 || 11:00:00 || London - Tokyo
I have tried several MySQL string functions like explode, locate, trim but can’t get it to properly work. I’m not that familiar with MySQL string functions so I’m having a hard time getting this to work. Any ideas on how to do this will be appreciated. Thanks a lot!
EDIT:
I’m not limiting the possible solutions to MySQL string functions only. Of course I’m open to PHP solutions as well. I just stated what I’ve done so far to get this work. Thanks.
While this is technically possible to do purely in MySQL, what makes you think it’s your only option?
It’s really far easier to do string parsing in PHP.