Beginner question about arrays

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
B. Palmer
Forum Newbie
Posts: 4
Joined: Mon Apr 09, 2012 3:54 pm

Beginner question about arrays

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Beginner question about arrays

Post 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?
B. Palmer
Forum Newbie
Posts: 4
Joined: Mon Apr 09, 2012 3:54 pm

Re: Beginner question about arrays

Post 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.
Post Reply