A
A
Alexey2018-04-03 10:08:24
PHP
Alexey, 2018-04-03 10:08:24

How to merge php lines into one?

Good day! Essence of a question: I am engaged in parsing of excel of the table, with the subsequent entering of the data from it into MySQL. I am using the phpexcel library. There is a table of the form
5ac3276571d8f236403331.png
I get data from it and the database is entered like this:
5ac327aac94f4693032564.png
I need to combine data from several lines so that they are in one line, something like this:
5ac327da04823541734002.png
Ie . you need to either combine using PHP or MYSQL (it didn’t work via CONCAT :( ) or something else.
Any ideas how this can be implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Viktor Yanyshev, 2018-04-03
@villiwalla

$a = 'string';
$b = 'string';
$columnName = $a.' '.$b;

L
Lone Ice, 2018-04-03
@daemonhk

Get data, compare, and shove the last line into the array to the same record (current), then join it and forward to the database.

S
Sergey Korenevsky, 2018-04-07
@Dier_Sergio_Great

See, after parsing we have an array

objects
$table_excel.
$arr_new = [];
$A = 0;
foreach($table_excel as &$row){
    if($row->A){
        $A = $row->A;
        $arr_new[$A] = &$row;
    }else{
        $arr_new[$A]['F'] .= ",$row->F";
    }
}
//$arr_new - Массив который теперь можно заносить в базу, где группировка сделанная по полю F

PS if the source data is not an array of objects but an array of arrays, then in the code you replace $row->A and $row->F with $row['A'] and $row['F'] respectively.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question