Hi! my name is Peter. iam working on the php platform.
while trying to run and compile a program i get the undefined offset error
iam nto much familiar with this error . Please help me . Thanks in advance.
Error: Undefined offset: 0 in /es/ePrintsStats/includes/inc.html.cumulative_usage.es.php on line 16
The code: -
<?php
-
$current_year = date("Y");
-
$last_year = date("Y")-1;
-
-
?>
-
<p>Most viewed eprints:
-
[<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date;range=4w">Past four weeks</a>]
-
[<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date;year=<?php print $current_year; ?>">This year</a>]
-
[<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date;year=<?php print $last_year; ?>">Last year</a>]
-
[<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date">All years</a>]
-
<br />Repository-wide statistics:
-
[<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=cumulative_usage;range=all">by Year/month</a>]
-
[<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=cumulative_usage_country">by Country</a>]
-
</p>
-
<?php
-
$max_count = $GLOBALS["db_values"][0]["abstracts"];
-
for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
-
{
-
if($max_count < $GLOBALS["db_values"][$rs]["abstracts"])
-
$max_count = $GLOBALS["db_values"][$rs]["abstracts"];
-
}
-
$max_width = '500'; // Max pixel width of barchart.
-
-
@
-
print '<font face="Arial" size="-1">Click on a month to see document downloads for that month.</font>';
-
print "<table>\n";
-
print '<tr><th bgcolor="#cccccc">Periods</th>
-
<th bgcolor="#66ddee">Abstracts</th>
-
<th bgcolor="#4477dd"><font color="#ffffff">Downloads</th>
-
<th bgcolor="#cccccc"> </th></tr>';
-
for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
-
{
-
$monthnum = (int) strpos('JanFebMarAprMayJunJulAugSepOctNovDec', $GLOBALS["db_values"][$rs]["month"])/3 + 1;
-
print '<tr><td><font face="Arial" size="-1"><a href="'.
-
$_SERVER['PHP_SELF'].
-
'?action=show_detail_date;year='.
-
$GLOBALS["db_values"][$rs]["year"].
-
';month=' .
-
$monthnum .
-
'">' .
-
$GLOBALS["db_values"][$rs]["year"].
-
' '.
-
$GLOBALS["db_values"][$rs]["month"].
-
'</a></font></td><td align="right"><font face="Arial" size="-1">'.
-
$GLOBALS["db_values"][$rs]["abstracts"].
-
'</font></td><td align="right"><font face="Arial" size="-1">'.
-
$GLOBALS["db_values"][$rs]["downloads"].
-
'</font></td>';
-
$cur_count = $GLOBALS["db_values"][$rs]["abstracts"];
-
$col_width = (int) ($cur_count/$max_count * $max_width);
-
$col_width = max($col_width, 1);
-
$col_width .= "px";
-
print '<td align="left"><img src="bars/hh.png" alt="abstracts" height="9" width="'.
-
$col_width .
-
'"><br />';
-
$cur_count = $GLOBALS["db_values"][$rs]["downloads"];
-
$col_width = (int) ($cur_count/$max_count * $max_width);
-
$col_width = max($col_width, 1);
-
$col_width .= "px";
-
print '<img src="bars/hp.png" alt="downloads" height="9" width="'.
-
$col_width .
-
'"></td></tr>';
-
}
-
print "</table>\n";
-
?>
-
6 4460 Please read the Posting Guidelines before you post in this forum! Especially the part about enclosing code within code or php tags!
And what is line 16?
Ronald :cool:
Please read the Posting Guidelines before you post in this forum! Especially the part about enclosing code within code or php tags!
And what is line 16?
Ronald :cool:
Thanks for the Reply,
line 16 is $max_count = $GLOBALS["db_values"][0]["abstracts"];
Undefined offset: 0 is the error that i come accross in the above line (line 16).
Okay .. think I'm just staring at this too long .. I have a random banner script that works just fine .. except one line is generating Undefined offset: 1 errors ...
The full script is .. -
<?php
-
-
-
$banner_File = "754.txt" ;
-
$total_Bannersize = 8 ;
-
-
-
-
$rnd_Value = Get754(0, $total_Bannersize-1);
-
$banner_Data = Get754Info($banner_File, $rnd_Value) ;
-
-
$Banner = split("::",$banner_Data);
-
-
$banner_Content = <<<content
-
-
<!-- Banner Ads Start -->
-
<a title="$Banner[2]" href="$Banner[1]" target="_blank"> <img name="Banner" src="$Banner[0]" alt = "$Banner[2]" border=0>
-
</a>
-
<!-- Banner Ads Ends -->
-
-
content;
-
-
echo $banner_Content ;
-
-
-
function Get754Info($filename, $line_number) {
-
-
$fp = @fopen($filename, "r")
-
or die ("Can't open file $filename on Line: " . __LINE__ . " in File: " . __FILE__);
-
-
$lnCounter = 0 ;
-
-
while (!feof ($fp)) {
-
$data = fgets($fp, 1024);
-
-
If ($lnCounter == $line_number){
-
$right_data = $data ;
-
return $right_data ;
-
break;
-
}
-
-
$lnCounter++ ;
-
}
-
}
-
-
-
function Get754($min, $max){
-
$mtime = ((double)microtime()* 100000) ;
-
$mtime = explode(" ", $mtime);
-
$mtime = floatval($mtime[1]) + floatval($mtime[0]) ;
-
$randval = mt_rand($min, $max);
-
return ($randval) ;
-
}
-
-
?>
-
The line returning the error is Line 50 .. - $mtime = floatval($mtime[1]) + floatval($mtime[0]) ;
What am I not seeing?
Oh .. PHP 5.0.4 ...
Thanks.
-bolo
Atli 5,058
Expert 4TB
Hi, bolo, and welcome to TSDN!
You are trying to split a double value by using a space character. A double value has no space characters so it will not be split, but the entire value ends up in array index 0. -
function Get754($min, $max){
-
// This line will return something like 12345.54321
-
$mtime = ((double)microtime()* 100000) ;
-
-
// And this line tries to split on " " char, which doesn't exist
-
$mtime = explode(" ", $mtime);
-
-
// So $mtime[1] doesnt exist, ergo PHP returns a warning.
-
$mtime = floatval($mtime[1]) + floatval($mtime[0]) ;
-
-
// These two lines apear to be the only relevent lines.
-
// The other lines are redundant, from what I can tell.
-
$randval = mt_rand($min, $max);
-
return ($randval) ;
-
}
-
Hi Atli ..
YOU are a freakin' genius. Took the lines out. Everything still works. No error.
Thanks.
-bolo
Atli 5,058
Expert 4TB
Hi Atli ..
YOU are a freakin' genius. Took the lines out. Everything still works. No error.
Thanks.
-bolo
Glad I could help :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lawrence |
last post by:
I just switched error_reporting to ALL so I could debug my site. I got
a huge page full of errors. One of the most common was that in my
arrays I'm using undefined offsets and indexes. These still...
|
by: Steven |
last post by:
Hi All,
I am moving some php code from a Linux machine to a Windows 2000 machine
with the code belowe I get the following error :
Notice: Undefined offset: 1 in c:\inetpub\wwwroot\test.php on...
|
by: google |
last post by:
Hello,
I'm having major problems trying to get my head round this problem.
I'm trying to generate an error free script, however, I still cannot
sort out this loop.
I get a "Notice:...
|
by: Richard Lawrence |
last post by:
Hi there,
I'm having a problem with PHP which I'm not sure how to best solve.
Here is the code:
$fp = fopen("comments.txt", "r");
while(!feof($fp))
{
$line = fgets($fp, 1024);
list($key,...
|
by: pareshgoel |
last post by:
class B
{
virtual ~B();
}
class D:public B
{
virtual ~D();
}
|
by: vfunc |
last post by:
I get compile error:
undefined reference to snd_pcm_format_width.
I included the library directory with -I flag on gcc.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include...
|
by: delusion7 |
last post by:
I am getting this error "Undefined offset: 9 in C:\Course Technology\1687-5\Chapter.10\UpdateContactInfo.php on line 36"
this is the code I am recieving the error on:
if...
|
by: simple12 |
last post by:
Hello
I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i...
|
by: neridaj |
last post by:
Hello,
I'm trying to figure out how to get rid of these errors:
Notice: Undefined offset: 1 in output_fns.php on line 315
Notice: getimagesize() : Read error! in
output_fns.php on line 315...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |