473,372 Members | 1,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Undefined offset error in php code.

3
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         $current_year = date("Y");
  3.         $last_year = date("Y")-1;
  4.  
  5. ?>
  6. <p>Most viewed eprints:
  7. [<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date;range=4w">Past four weeks</a>]
  8. [<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date;year=<?php print $current_year; ?>">This year</a>]
  9. [<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date;year=<?php print $last_year; ?>">Last year</a>]
  10. [<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=show_detail_date">All years</a>]
  11. <br />Repository-wide statistics:
  12. [<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=cumulative_usage;range=all">by Year/month</a>]
  13. [<a href="<?php print $_SERVER['PHP_SELF']; ?>?action=cumulative_usage_country">by Country</a>]
  14. </p>
  15. <?php
  16.             $max_count = $GLOBALS["db_values"][0]["abstracts"];
  17.             for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
  18.         {
  19.                 if($max_count < $GLOBALS["db_values"][$rs]["abstracts"])
  20.                         $max_count = $GLOBALS["db_values"][$rs]["abstracts"];
  21.         }
  22.         $max_width = '500'; // Max pixel width of barchart.
  23.  
  24. print '<font face="Arial" size="-1">Click on a month to see document downloads for that month.</font>';
  25. print "<table>\n";
  26.         print '<tr><th bgcolor="#cccccc">Periods</th>
  27.                 <th bgcolor="#66ddee">Abstracts</th>
  28.                 <th bgcolor="#4477dd"><font color="#ffffff">Downloads</th>
  29.                 <th bgcolor="#cccccc">&nbsp;</th></tr>';
  30.         for ($rs=0;$rs<count($GLOBALS["db_values"]);$rs++)
  31.         {
  32.                 $monthnum = (int) strpos('JanFebMarAprMayJunJulAugSepOctNovDec', $GLOBALS["db_values"][$rs]["month"])/3 + 1;
  33.                 print '<tr><td><font face="Arial" size="-1"><a href="'.
  34.                         $_SERVER['PHP_SELF'].
  35.                         '?action=show_detail_date;year='.
  36.                         $GLOBALS["db_values"][$rs]["year"].
  37.                         ';month=' .
  38.                         $monthnum .
  39.                         '">' .
  40.                         $GLOBALS["db_values"][$rs]["year"].
  41.                         ' '.
  42.                         $GLOBALS["db_values"][$rs]["month"].
  43.                         '</a></font></td><td align="right"><font face="Arial" size="-1">'.
  44.                         $GLOBALS["db_values"][$rs]["abstracts"].
  45.                         '</font></td><td align="right"><font face="Arial" size="-1">'.
  46.                         $GLOBALS["db_values"][$rs]["downloads"].
  47.                         '</font></td>';
  48.                 $cur_count = $GLOBALS["db_values"][$rs]["abstracts"];
  49.  $col_width = (int) ($cur_count/$max_count * $max_width);
  50. $col_width = max($col_width, 1);
  51.                 $col_width .= "px";
  52.                 print '<td align="left"><img src="bars/hh.png" alt="abstracts" height="9" width="'.
  53.                         $col_width .
  54.                         '"><br />';
  55.                 $cur_count = $GLOBALS["db_values"][$rs]["downloads"];
  56.                 $col_width = (int) ($cur_count/$max_count * $max_width);
  57.                 $col_width = max($col_width, 1);
  58.                 $col_width .= "px";
  59. print '<img src="bars/hp.png" alt="downloads" height="9" width="'.
  60. $col_width .
  61.                         '"></td></tr>';
  62.         }
  63.         print "</table>\n";
  64. ?>
  65.  
Jan 22 '07 #1
6 4456
ronverdonk
4,258 Expert 4TB
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:
Jan 22 '07 #2
nicy12
3
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).
Jan 22 '07 #3
bolo
2
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 ..

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. $banner_File = "754.txt" ; 
  5. $total_Bannersize = 8 ;        
  6.  
  7.  
  8.  
  9. $rnd_Value = Get754(0, $total_Bannersize-1);
  10. $banner_Data = Get754Info($banner_File, $rnd_Value) ;
  11.  
  12. $Banner = split("::",$banner_Data);
  13.  
  14. $banner_Content = <<<content
  15.  
  16. <!-- Banner Ads Start -->
  17. <a title="$Banner[2]" href="$Banner[1]" target="_blank"> <img name="Banner" src="$Banner[0]" alt = "$Banner[2]" border=0>
  18. </a>
  19. <!-- Banner Ads Ends -->
  20.  
  21. content;
  22.  
  23. echo  $banner_Content  ;
  24.  
  25.  
  26. function Get754Info($filename, $line_number) {
  27.  
  28.          $fp = @fopen($filename, "r")
  29.                 or die ("Can't open file $filename on Line: " . __LINE__ . " in File: " . __FILE__);
  30.  
  31.          $lnCounter = 0 ;
  32.  
  33.          while (!feof ($fp)) {
  34.               $data = fgets($fp, 1024);
  35.  
  36.                If ($lnCounter == $line_number){
  37.                        $right_data = $data ;
  38.                        return $right_data ;
  39.                        break;
  40.                  }
  41.  
  42.                  $lnCounter++ ;
  43.         }
  44. }
  45.  
  46.  
  47. function Get754($min, $max){
  48.          $mtime = ((double)microtime()* 100000) ;
  49.          $mtime = explode(" ", $mtime);
  50.          $mtime = floatval($mtime[1]) + floatval($mtime[0]) ;
  51.          $randval = mt_rand($min, $max);
  52.          return ($randval) ;
  53. }
  54.  
  55. ?>
  56.  
The line returning the error is Line 50 ..

Expand|Select|Wrap|Line Numbers
  1. $mtime = floatval($mtime[1]) + floatval($mtime[0]) ;
What am I not seeing?

Oh .. PHP 5.0.4 ...

Thanks.

-bolo
Aug 11 '07 #4
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.

Expand|Select|Wrap|Line Numbers
  1. function Get754($min, $max){
  2.          // This line will return something like 12345.54321
  3.          $mtime = ((double)microtime()* 100000) ;
  4.  
  5.          // And this line tries to split on " " char, which doesn't exist
  6.          $mtime = explode(" ", $mtime);
  7.  
  8.          // So $mtime[1] doesnt exist, ergo PHP returns a warning.
  9.          $mtime = floatval($mtime[1]) + floatval($mtime[0]) ;
  10.  
  11.          // These two lines apear to be the only relevent lines.
  12.          // The other lines are redundant, from what I can tell.
  13.          $randval = mt_rand($min, $max);
  14.          return ($randval) ;
  15. }
  16.  
Aug 11 '07 #5
bolo
2
Hi Atli ..

YOU are a freakin' genius. Took the lines out. Everything still works. No error.

Thanks.

-bolo
Aug 11 '07 #6
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 :)
Aug 11 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
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...
1
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:...
4
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,...
3
by: pareshgoel | last post by:
class B { virtual ~B(); } class D:public B { virtual ~D(); }
8
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...
3
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...
9
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.