user863317
user863317

Reputation:

Print_r array problem

I have the following code:

<?php
    mysql_connect("localhost", "root", "");
    mysql_select_db("coockie");

    $filename ="excelreport.xls";
    $contents = "date \t ip \t visits \t \n";

    $result=mysql_query("select * from test");

    $mydate='';
    $myip='';
    $visits='';

    while($data=mysql_fetch_assoc($result))
    {
        $mydate.=explode(",", $data['date']);
        $myip.=explode(",", $data['ip']);
        $visits.=$data['visits'];

    }

    print_r($mydate);

    //header('Content-type: application/ms-excel');
    //header('Content-Disposition: attachment; filename='.$filename);
    //echo $contents;
?>

$mydate is outputted as string Array. I need it outputted like array of values. Any suggestions?

Upvotes: 0

Views: 3585

Answers (2)

Johan
Johan

Reputation: 5053

You might want to try var_dump instead of print_r. At least for debugging purposes.

var_dump($mydate);

Upvotes: 2

J0HN
J0HN

Reputation: 26951

You are misusing string concatenation operator .=

$mydate.=explode(",", $data['date']);

explode gives you an array, and with .= it's converted to string Array. The proper way is to use [] operator

$mydate=array();
$myip=array();
$visits='';

while($data=mysql_fetch_assoc($result))
{
    $mydate[]=explode(",", $data['date']);
    $myip[]=explode(",", $data['ip']);
    $visits.=$data['visits'];

}

print_r($mydate);

Upvotes: 2

Related Questions