Undefined offset: 1 ERROR

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Undefined offset: 1 ERROR

Post by mcccy005 »

Alrighty; well like the title says; the error I'm getting is this:

Notice: Undefined offset: 1 in D:\XXXXXX\Web_Pages\Object_Library\Result_Fields\results.php on line 47

The code goes like this. I'm parsing most of an SQL query to this webpage (results.php). The query for simplicity is as follows:

select student.name from students;

The code in results.php then adds a "LIMIT" and "ORDER BY" paramater at the end of the query like this:

Code: Select all

//$sql_query="select student.name from students";
//$titles=array("Student Name");


/*stores the column number to be sorted */
   if(@!empty($_GET['column'])) $column=$_GET['column'];
   else $column = 1;
   
   $LIMIT=($num_results*$current_page) - $num_results;
		
/*Query to select information from the database */
   $sql_query.=" LIMIT '{$LIMIT}'

<<Line 47>> ORDER BY '{$titles[$column]}' '{$order}'";
NOTE also that $titles is an array parsed to results.php along with $sql_query

Any ideas???

Thanks
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

OOPS - I'm an idiot.

I'm using "ORDER BY" but not specifying the actual proper name that is in the database!!

Hopefully I can fix that!!
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Undefined Offset -> means you are trying to access a array place holder outside of the array range. How many values do you have in your $titles array, remember that arrays are zero based.
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

haha yep - i sorted that problem out too - i was trying to access $titles at position 1 when therre was only 1 value in there! (So it should have been position 0)
But thanks for the info - its not something I was aware of until now....I just assumed it was some mysql connection error.
Post Reply