473,770 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined offset error in php code.

3 New Member
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.cumula tive_usage.es.p hp 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 4480
ronverdonk
4,258 Recognized Expert Specialist
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 New Member
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 New Member
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 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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
108841
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 work fine, but with error reporting at all they are marked as errors. Why? What am I doing wrong? www.monkeyclaus.org
2
25825
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 line 5 1) reset($kolom1); 2) while(list($cat,$lnk) = each($kolom1)){ 3) kop($cat);
1
4584
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: Undefined offset: 24 in c:\inetpub\wwwroot\classes\file.php on line 348"
4
10192
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, $value) = explode(":", $line, 2);
3
1671
by: pareshgoel | last post by:
class B { virtual ~B(); } class D:public B { virtual ~D(); }
8
3547
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 <sched.h> #include <errno.h> #include <getopt.h>
3
3295
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 (mysqli_num_rows($QueryResult) > 0) { $Row = mysqli_fetch_row($QueryResult); $First = stripslashes($Row); $Last = stripslashes($Row); $Phone = stripslashes($Row); $Address = stripslashes($Row); $City = stripslashes($Row); $State = stripslashes($Row);
9
32504
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 try to not use a code and leave it empty the following php errors happens. I dont understand why. Help me. Error shown are: - PHP Notice: in file /index.php on line 132: Undefined offset: 4 PHP Notice: in file /index.php on line 141:...
2
2689
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 function get_imgdim()
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.