GkNx
GkNx

Reputation: 169

fetch to array from mysql while

I am trying to fetch columns to array and then export it to excel. Here is my code. $addizi and $teldizi are arrays pulled from second table.

    $result = mysqli_query($con,"SELECT * FROM table WHERE date BETWEEN '$date1' and '$date2'");
        $i=1;
        $addizi = array();
        $teldizi = array();
        while($oku=mysqli_fetch_assoc($result))
        {
    $transida = $oku['id'];
    $result3it = mysqli_query($con,"SELECT * FROM table2 where transid = '$transida'");
            while($oku3it=mysqli_fetch_assoc($result3it))
            {

                $addizi[] = $oku3it['name'];
                $teldizi[] = $oku3it['tel'];


            }
            $row = array($addizi, $oku['from'],$oku['to'], $teldizi, date('d-m-Y', strtotime($oku['dateTr'])), $oku['timeTr']);
            $excel->addRow($row);
    $i++;
    }

    $excel->finalize();

The code exports excel file but data in second while does not exist. It does not export $addizi and $teldizi.

Thanks for your answers.

Upvotes: 0

Views: 38

Answers (1)

arueckauer
arueckauer

Reputation: 352

As already posted in the comment section. Here is the solution:

Instead of providing $addizi and $teldizi as array to $row, provide them as strings by calling implode(',', $addziz) and implode(',', $teldizi).

Upvotes: 1

Related Questions