Page 1 of 1

Beginner question about arrays

Posted: Mon Apr 09, 2012 4:03 pm
by B. Palmer
I have a very basic question. I inherited some PHP/Javascript/HTML code and new tools so I'm trying to learn everything simultaneously. Here's a snippet that's confusing me...

Code: Select all

		$enrollment->setSort(array('attributes' => array('*',
			'student.firstName' => array('asc' => 'student.firstName', 'desc' => 'student.firstName desc'),
			'student.lastName'  => array('asc' => 'student.lastName', 'desc' => 'student.lastName desc'),
			'icon'              => array('asc' => 'iconFile', 'desc' => 'iconFile desc'),
		)));
I'm trying to remove the icon so I commented out the last line of the code as follows:

Code: Select all

		$enrollment->setSort(array('attributes' => array('*',
			'student.firstName' => array('asc' => 'student.firstName', 'desc' => 'student.firstName desc'),
			'student.lastName'  => array('asc' => 'student.lastName', 'desc' => 'student.lastName desc'),
//			'icon'              => array('asc' => 'iconFile', 'desc' => 'iconFile desc'),
		)));
This is triggering an exception and I don't understand why. I believe the code is taking the student's first name and description and putting it into the 'student.firstName' array. Then it's repeating the process for the 'student.lastName' array and the 'icon' array and then putting all three arrays into the 'attributes' array. If this is correct, why would simply removing the 'icon' array from the 'attributes' array trigger an exception.

Thanks in advance. B

Re: Beginner question about arrays

Posted: Mon Apr 09, 2012 7:13 pm
by Celauran
This looks like's it just setting the possible ORDER BY clauses to be used in a query. Is that really what you're trying to remove?

Re: Beginner question about arrays

Posted: Tue Apr 10, 2012 12:36 pm
by B. Palmer
Yes. I want to remove the icon field entirely, so I need to remove it from the sort. The exception I'm getting is "classroom.student is not defined".

Does the setSort call automatically try to access the database? Because that's what appears to be happening. I don't understand why removing a field from the sort would be a problem.