Php will not show all transaktions if too many digits

Hi
I am new in this forum, but I hope its ok ask for a little help.
I have installed a virtual server and NetBeans and taught myself some php and mysql and have successfully created some programs to give me an overview of our daily finances.
I have processed the bank statements and created some database files. BUT - now I’ve gotten to the point where I want to show it all on the screen, but have run into a problem I can’t figure out.
I have made a small simple code snippet which shows the problem. Hope it makes sense.

<!DOCTYPE html>
    <head>
        <meta charset="UTF-8">
        <title>Vis sumtotaler i kolonner pr. md.</title>
        <link rel="stylesheet" href="Stylesheet_hjemmeside.css" type="text/css"/>   
     </head>
    <body>
                
<?php

$sti2 ="totale_saldi_1.csv";
           $csv = array(13);
           $handle1 = fopen($sti2, "r") or die("can't open file");
  
           while (($info = fgetcsv($handle1, 120, ";")) !==false)      
    {     
            if (empty($info[0]))
            {
            goto stop;
            }   
            
            if (empty($info[1]))
            {
            $info[1] = 0;
            } 
            
            if (empty($info[2]))
            {
            $info[2] = 0;
            }      
  
            if (empty($info[3]))
            {
            $info[3] = 0;
            } 
            
            if (empty($info[4]))
            {
            $info[4] = 0;
            }   
            
            if (empty($info[5]))
            {
            $info[5] = 0;
            } 
            
            if (empty($info[6]))
            {
            $info[6] = 0;
            }  
            
            if (empty($info[7]))
            {
            $info[7] = 0;
            }      
  
            if (empty($info[8]))
            {
            $info[8] = 0;
            } 
            
            if (empty($info[9]))
            {
            $info[9] = 0;
            }   
            
            if (empty($info[10]))
            {
            $info[10] = 0;
            } 
            
            if (empty($info[11]))
            {
            $info[11] = 0;
            }
            
            if (empty($info[12]))
            {
            $info[12] = 0;
            }      
        
echo "<table style=\"border-style: solid;border-width: thin;border-collapse: collapse;\">";
echo "<tr><td style=\"text-align:center;padding-center:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:lightgrey;color:black; width:100px;font-size: 12px\">";
echo $info[0];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[1];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo$info[2];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[3];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[4];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[5];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo$info[6];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[7];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[8];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[9];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[10];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[11];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo $info[12];
echo "</td><td style=\"text-align:right;padding-right:5px;border-style: solid;border-width: thin;border-collapse: collapse;background-color:#AFEEEE ; color:black; width:80px;font-size: 12px\">";
echo "</td></tr>";
echo "</table>"; 

stop:
    }

The data in this code snippet comes from a .csv file:

Month;1;2;3;4;5;6;7;8;9;10;11;12
Special income; 4100.00;4100.00;4100.00;4100.00;4100.00;4100.00;4100.00;4100.00;4100.00; 4100.00;4100.00;4100.00;
Normal income - salary; 20627.00;20627.00;20627.00;20627.00;20627.00;20627.00;20627.00; 20627.00;20627.00;20627.00;20627.00;20627.00;
Rent,electricity and water;-13000.00;-13000.00;-13000.00;-13000.00;-13000.00; -13000.00; -13000.00;-13000.00;-13000.00;-13000.00;-13000.00;-13000.00;

The output on screen looks like this:
Month 1 2 3 4 5 6
Special income 4100.00 4100.00 4100.00 4100.00 4100.00 4100.00
7 8 9 10 11 12
4100.00 4100.00 4100.00 4100.00 4100.00 4100.00
1 2 3 4 5 6
Normal income - salary 20627.00 20627.00 20627.00 20627.00 20627.00 20627.00
7 8 9 10 11 12
20627.00 20627.00 20627.00 20627.00 20627.0 0
1 2 3 4 5 6
Rent,electricity and water -13000.00 -13000.00 -13000.00 -13000.00 -13000.00 -13000.00
7 8 9 10 11 12
-13000.00 -13000.00 -13000.00 -13 0 0

As you see in the .csv file - all 3 data lines contains 12 times an amount.
The first one with a small monthly amount shows 12 times 4100.00
The sesond line with a large amount shows 10 times 20627.00 and one time 20627.0 (one decimal) and one time zero
The third line with a negativ amount shows 9 times -13000.00, one time -13 and 2 times zero
eg har testet, at hvis jeg reducerer teksten, bliver der plads til flere cifre.
Det ser ud som om der er en begrænsning et eller andet sted.
Er der nogen der har har en ide om, hvad der er galt ???
thanks in advance
Freddy

sorry - I can see, that all my line breaks disapeared when I submitted it.
I would have sent a screenshot. but i could not see how
Freddy

To format your code, either use bbcode code tags or markdown three back-ticks, on separate lines before and after your code. I have edited your first post to add these.

translated to English
I have tested that if I reduce the text, there is room for more digits.
It looks like there is a limitation somewhere.
Does anyone have any idea what is wrong???

to phdr - I will remember that in the future - thank you very much

The reason for the output being split, is because the fgetcsv() is only reading 120 characters at a time. The length parameter needs to be larger than the longest expected line.

Here’s what I came up with for what this code is doing -

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Vis sumtotaler i kolonner pr. md.</title>
<style>
table {
    border-style: solid;
    border-width: thin;
    border-collapse: collapse;
}

td {
    text-align: right;
    padding-right: 5px;
    border-style: solid; 
    border-width: thin; 
    border-collapse: collapse;
    background-color: #AFEEEE;
    color: black;
    width: 80px;
    font-size: 12px;
}

td.heading {
    text-align: center;
    padding-center: 5px; 
    border-style: solid; 
    border-width: thin; 
    border-collapse: collapse; 
    background-color: lightgrey;
    color: black; 
    width: 100px;
    font-size: 12px; 
}
</style>
<link rel="stylesheet" href="Stylesheet_hjemmeside.css" type="text/css"/>
</head>
<body>
<table>
<?php
// define a call-back function to change any 'empty' value to a literal 0 
function _zero($val)
{
	return empty($val) ? 0 : $val;
}

$sti2 ="totale_saldi_1.csv";
$handle1 = fopen($sti2, "r") or die("can't open file");
while (($info = fgetcsv($handle1, 256, ";")) !==false)
{
	// don't use goto. in this case, use continue
	if (empty($info[0]))
	{
		continue;
	}
	
	// the original repetitive code changes any 'empty' value to a literal 0
	// convert all the values at once
	$info = array_map('_zero',$info);
	
	// don't echo static markup. use a majority-rule. if most of the output is html, exit php, put the html inline, outputting only the dynamic value using php
	// if you do echo html, don't escape double-quotes, just use single quotes
	// use css rules for repetitive, common styling
	
	// the original code produces a new table for every row of data.
	// if you want a single table, the <table> and </table> tags need to be output before/after the looping

	// you should use a loop to produce the repeated output
	// the 1st td gets a specific css class
	$class = " class='heading'";
	echo '<tr>';
	foreach(range(0,12) as $x)
	{
		echo "<td$class>$info[$x]</td>";
		$class = '';
	}
?>
<td></td>
</tr>
<?php
}
?>
</table>

Thank you so much. I thought it was the length of the individual elements in the array that you specify. Next time I have to read the manual, I’d better put on my glasses. :slight_smile:
Also, thanks for the valuable comments and good advice.

Sponsor our Newsletter | Privacy Policy | Terms of Service