Ahatius
Ahatius

Reputation: 4875

Can't echo after certain line

I have some strange behaviour in my php script. For some reason, I can't create an echo, after a certain line.

include 'class/core.class.php';
include 'class/tp.class.php';

$tps = new tps;
$system = $_GET['system'];

$file = @fopen(getcwd() . "/csv/" . $system . ".csv", "r");
if(!$file) {
    echo "No data in " . getcwd() . "/csv";
    exit;
}

$tps->dropSystemData($system);

$counter = 0;

$data = array();

while($csv = fgetcsv($file, 0, ";")) {
    $data[$counter]['date'] = $csv[0];
    $data[$counter]['time'] = $csv[1];
    $data[$counter]['tp'] = $csv[2];

    $counter++;
}

foreach($data as $row) {
    $date = explode(".", $row['date']);
    echo 1; // Works
    $date = $date[2] . "/" . $date[1] . "/" . $date[0];
    echo 2; // Works
    $time = $row['time'];
    echo 3; // Works
    $tp = $row['tp'];
    echo 4; // Doesn't work
    echo $tp; // Doesn't work
    var_dump($tp); // Doesn't work
    var_dump($data); // This doesn't output anything like the echos and var_dumps before
}

I don't see any particular reason, why this shouldn't work. No errors at all.

Var_dump of $data

array(445) {
  [0]=>
  array(3) {
    ["date"]=>
    string(10) "03.01.2012"
    ["time"]=>
    string(8) "12:30:06"
    ["tp"]=>
    string(10) "EN1K945540"
  }
  [1]=>
  array(3) {
    ["date"]=>
    string(10) "04.01.2012"
    ["time"]=>
    string(8) "12:30:07"
    ["tp"]=>
    string(10) "EN1K945588"
  }
  [2]=>
  array(3) {
    ["date"]=>
    string(10) "04.01.2012"
    ["time"]=>
    string(8) "12:30:09"
    ["tp"]=>
    string(10) "EN1K945592"
  }
  [3]=>
  array(3) {
    ["date"]=>
    string(10) "04.01.2012"
    ["time"]=>
    string(8) "12:30:09"
    ["tp"]=>
    string(10) "EN1K945594"
  }

Added the following to the beginning, but no errors or warnings:

error_reporting(E_ALL);
ini_set('display_errors', '1');

Update: I've changed the variable names now, but it still doesn't work.

Update 2: My bad, some caching issue, now closed and opened browser, now it's working. The duplicate variable names caused the problems.

Upvotes: 0

Views: 358

Answers (2)

Palantir
Palantir

Reputation: 24182

Are you in a browser? Does your $row['tp']; contain invalid HTML code or an angular brace? They may be interpreted as HTML tags and therefore no code may be shown. Check in the HTML/source...

Upvotes: 1

DonCallisto
DonCallisto

Reputation: 29942

You do $tp = new tp; and assing to $tp an instance of tp Class

Into the cycle, instead, you assign it a String and that mess all the things up

Upvotes: 3

Related Questions