I have the following problem:
If the string is: 1 x somethingbr
1 x something elsebr
2 x something even different
I want that to insert into my mysql database as follows: 1 something 1 something else 2 something even different
So we need to separate each line that needs to be inserted when there is a br
, also split (explode) where there is a " x " for a new column and insert the first part into the 1st column and the 2nd part in the 2nd column.
Thanks!
Try with this..
<?php
$string = '1 x something <br> 1 x something else <br> 2 x something even different';
$lines = explode('<br>', $string);
foreach($lines AS $line){
list($quantity, $item) = explode('x', $line);
$sql = sprintf('INSERT INTO TABLE (field_for_quantity, field_for_item) VALUES (%u, "%s")', $quantity, $item);
mysql_query($sql);
}
?>