PHP Classes

Undefined offset

Recommend this page to a friend!

      Cascade Dropdown 3 Levels  >  All threads  >  Undefined offset  >  (Un) Subscribe thread alerts  
Subject:Undefined offset
Summary:Error when altering MySQL example tables provided with the code
Messages:2
Author:Joe Lalicata
Date:2009-05-13 09:07:55
Update:2009-07-18 08:30:45
 

 


  1. Undefined offset   Reply   Report abuse  
Picture of Joe Lalicata Joe Lalicata - 2009-05-13 09:07:55
Hi Gobinath,

I am an amateur PHP programmer. When I import the MySQL file (unaltered) into my database and run the code, the cascade dropdowns work like a champ. If I alter the data in the "Type" table but keep the same number of rows, I'm fine. If I add more rows to any of the other tables (Brand & Model), I'm still fine. However, if I add another row to the Type table, and then open up my webpage, I get the following error:

Notice: Undefined offset: 2 in C:\wamp\www\mydomain.com\scripts\DynamicDropDown.class.php on line 94

Line 94 seems to be:
$this->arrType[$this->IDx][$i]= $this->typeRow[$i]; // Store the Value of the Type table to the Array

I am running WampServer v2.0 on XP Home Edition (SP3). Thanks in advance!

Joe

  2. Re: Undefined offset   Reply   Report abuse  
Picture of dennis gaya dennis gaya - 2009-07-18 08:30:45 - In reply to message 1 from Joe Lalicata
Dennis Gaya, Nairobi, Kenya

The error shows that the resulting array values for $i are undefined. eg. 4=1,2,3,4.. ETC.
Here is a quick Solution
function DataFetch(){
//Suggestions: The Table names can be changed according to the User. But be carefull with the Query and other variables
// So that the Script will function Properly

$this->typeSql="select * from e_categories"; //Query to fetch the Data from the table "type"
$this->typeResult=mysql_query($this->typeSql); //Execute the Query and Store the result in new variable

$numrows=mysql_num_rows($this->typeResult);
// Start fetching the Values from the Result Resource (typeResult)
while ( $this->typeRow = mysql_fetch_array($this->typeResult,MYSQL_BOTH)){ // TYPE table Fetch While Loop begins Here
for($i=0;isset($this->typeRow[$i]);$i++){
//for($i=0; isset($sponsorheading[$i]); $i++){
$this->arrType[$this->IDx][$i]= $this->typeRow[$i]; // Store the Value of the Type table to the Array
}

Regards
Dennis Gaya, Nairobi, Kenya
dennisgaya@yahoo.com