I'm working on a education site for swedish-english language.
In my articles has example sentences, and I've enter these words into textarea. Its easily save my texts to database. But I want to insert my texts in one row like
id -- swedish_text -- english_text -- sort
1 -- text_sw -- text_en -- 1
Currently Im using this style for insert
id -- example -- sort
1 -- text1_sw -- 1
2 -- text1_en -- 2
Textarea import loop;
$exWords = explode(PHP_EOL, $_POST['ex_words']);
foreach($exWords as $k=>$v){
$myconn->query("INSERT INTO words SET example='" . $v . "',sort=". $k ."");
};
Thank you!
So you will just want to use two separate columns in each database row, you will ave to modify your schema to match your desired structure.
When you set the data, just set the two columns with the correct data.
SET column1="x",column2="y"
Be careful of injection, make sure to use proper escaping, especially if the users can supply this information.
I found my solution;
# Example $_POST['ex_words'] Content
# Text swe1
# Text eng1
# Text swe2
# Text eng2
$exWords = explode(PHP_EOL, $_POST['ex_words']);
$exWords = array_chunk($exWords,2);
foreach($exWords as $k=>$v){
$exwData = array(
'word_id'=>$wordID,
'ex_word1'=>$v[0],
'ex_word2'=>$v[1],
'word_sort'=>$k
);
$db->insert('exwords',$exwData);
}
Thanks!