Error Notice: Undefined offset: 1 …bla..bla…

jika kita mempunyai code seperti dibawah ini dengan inputan dari file txt :

untuk file txtnya bisa diunduh disini : http://www.mediafire.com/?p5lwcmx687xcc53

<html>
<head>

<style type="text/css" media="screen"> 
table#family{ 
width:400px; 
margin:0 auto; 
border-collapse:collapse; 
border:1px solid #ccc; 
} 
</style> 

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="table/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="table/jquery.gvChart-1.0.1.min.js"></script>
<script type="text/javascript">
		gvChartInit();
		jQuery(document).ready(function(){
			jQuery('#myTable1').gvChart({
				chartType: 'AreaChart',
				gvSettings: {
					vAxis: {title: 'No of players'},
					hAxis: {title: 'Month'},
					width: 720,
					height: 300
					}
			});
</script>
<style>
			body{
				text-align: center;
				font-family: Arial, sans-serif;
				font-size: 12px;
			}
			
			a{
				text-decoration: none;
				font-weight: bold;
				color: #555;
			}
			
			a:hover{
				color: #000;
			}
			
			div.main{
				margin: auto;
				text-align: left;
				width: 720px;
			}
		
			div.clean{
				border: 1px solid #850000;
			}
			
			.clean td, .clean th{
				border: 2px solid #bbb;
				background: #ddd;
				padding: 5px 10px;
				text-align: center;
				border-radius: 2px;
			}
			
			.clean table{
				margin: auto;
				margin-top: 15px;
				margin-bottom: 15px;
			}
			
			.clean caption{
				font-weight: bold;
				
			}
			
			.gvChart,.clean{
				border: 2px solid #850000;
				border-radius: 5px;
				-moz-border-radius: 10px;
				width: 720px;
				
				margin: auto;
				margin-top: 20px;
			}
			
			pre{
				background: #eee;
				padding: 10px;
				border-radius: 10px;
				-moz-border-radius: 10px;
			}
		</style>
</head>
<body>
<table id='myTable1' width="1362" border="1" cellspacing="2">
	<thead>
		<tr>
			<td width="41">ID</td>
			<td width="56">Tag</td>
			<td width="103">CollectTime</td>
			<td width="73">Sample</td>
			<td width="98">MOS-min</td>
			<td width="162">MOS-max</td>
			<td width="240">RTT-avg</td>
			<td width="256">RTT-min</td>
			<td width="275">RTT-Max</td>
		</tr>
	
<?php

function explodeRows($data){
	$rowsArr = explode("\n",$data);
	return $rowsArr;
}
function explodeTabs($singleLine){
	$tabsArr = explode("|",$singleLine);
	return $tabsArr;
}
//azani function
function readLine($data, $line_number)
{
        /*** read the file into the iterator ***/
        $file_obj = new SplFileObject( $data );

        /*** seek to the line number ***/
        $file_obj->seek( $line_number );

        /*** return the current line ***/
        return $file_obj->current();
}


$filename = "ping-192.168.2.1.txt";
$handle   = fopen($filename, 'r');
$data 	  = fread($handle,filesize($filename));
$rowsArr   = explodeRows($data);
print count($rowsArr);
for($i=0;$i<count($rowsArr);$i++){

	$lineDetails = explodeTabs($rowsArr[$i]);
		print "<tr>\n";
		print "<td>" .$lineDetails[0]. "</td>\n";
		print "<td>" .$lineDetails[1]. "</td>\n";
		print "<td>" .$lineDetails[2]. "</td>\n";
		print "<td>" .$lineDetails[3]. "</td>\n";
		print "<td>" .$lineDetails[4]. "</td>\n";
		print "<td>" .$lineDetails[5]. "</td>\n";
		
		//print "<td>" .$line4. "</td>\n";
		//print "<td>" .$line5. "</td>\n";
		print "</tr>\n";
//	}
}


?>

</table>
</body>
</html>

maka akan menghasilkan tampilan dengan error sebagai berikut :

kenapa errror??? usut-punya usut ternyaya erorr dihasilkan dari kesalahan menghitung file yg dilakukan oleh

<count($rowsArr)

, karena count $rowsArr akan menghasilkan angka 51 yg membuat tidak didefinisikan. padahal jumlah row kita hanya sebesar 50 untuk mengatasi masalah tersebut kita tinggal hilangkan code count tersebut.
dan diganti dengan banyaknya jumlah file baris yg kita punya.

for($i=0;$i<50;$i++){

info didapat setelah dibimbing oleh mas azani..:D

2 thoughts on “Error Notice: Undefined offset: 1 …bla..bla…

  1. problem fixed..thanks ya🙂

    oh ya ada sedikit tambahan dari saya mungkin bung yaniar jg dah tau hehe…kalau kita tidak mengetahui jumlah baris yg ada di var array, bisa ditambahkan -1 setelah count .

    count($rowsArr)-1

    thanks bung yaniar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s