Page 1 of 1

Undefined offset: 1 ERROR

Posted: Wed Oct 11, 2006 2:49 am
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

Posted: Wed Oct 11, 2006 2:53 am
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!!

Posted: Wed Oct 11, 2006 3:20 am
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.

Posted: Wed Oct 11, 2006 5:33 am
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.