I have a codeigniter view where "echo" statement is not displaying the output - this happens only from a specific loop that I am giving below. I have tried to run it through a sample for loop with echo statement inside; it works without issues. In the code block below $results is an array returned from the controller. I have tried writing the values of the array to a file and they get written correctly.
foreach ($results as $row) {
fwrite($myfile,$row[0] . PHP_EOL); //this writes perfectly fine
echo "<tr><td>TEst . $row[0] </td>"; //this doesnt show up
}
i have tried other threads in this forum with subject "echo not working" - they do not match my peculiar case. Any help is appreciated
WAS:
echo "<tr><td>TEst . $row[0] </td>";
IS:
echo "<tr><td>TEst ".$row[0]."</td>";
If that doesn't work, you need to find out what your array really has in it, because it means there is no 0 key. Try,
print_r($row);
Try this...
foreach ($results as $row) {
fwrite($myfile,$row[0] . PHP_EOL);
echo '<tr><td>TEst'.$row[0].'</td></tr>';
}
try
if($results){
foreach ($results as $row) {
fwrite($myfile,$row[0] . PHP_EOL);
//try this
echo "<tr><td>TEst ".$row[0]."</td></tr>";
//or this
echo "<tr><td>TEst ".$row->keyname."</td></tr>";
//or this
echo "<tr><td>TEst ".$row['keyname']."</td></tr>";
}
}
else
{
echo "NO RESULTS";
}