This is my animals
table in the mySQL database:
| id | animal | name | number |
|----|--------|------|--------|
| 2 | cat | john | 6345 |
| 2 | mouse | fred | 7463 |
| 3 | monkey | noah | 2342 |
I insert data from a text file, which looks like this (for example):
animal=dog
name=alan
animal=frog
name=sam
animal=bird
name=mike
This is my code:
$id = 1
$sql = "INSERT INTO animals (animal,name,id) values(?,?,?)";
foreach($list as $row) {
$q->execute(array($row['animal'], $row['name'], $id));
}
After the insert my animals
table looks like this:
| id | animal | name | number |
|----|--------|------|--------|
| 1 | dog | alan | |
| 1 | frog | sam | |
| 1 | bird | mike | |
| 2 | cat | john | 6345 |
| 2 | mouse | fred | 7463 |
| 3 | monkey | noah | 2342 |
Later I have another text file which looks like this:
number=1425
number=9824
number=9932
The numbers are in exactly the same order like the data from the first text file. So what I want to do is just add the numbers, so that my table would look like this:
| id | animal | name | number |
|----|--------|------|--------|
| 1 | dog | alan | 1425 |
| 1 | frog | sam | 9824 |
| 1 | bird | mike | 9932 |
| 2 | cat | john | 6345 |
| 2 | mouse | fred | 7463 |
| 3 | monkey | noah | 2342 |
But I do not know how to do this in one statement. I hope you can help. Thank you very much!