Joomla! Discussion Forums



It is currently Tue Nov 24, 2009 3:48 pm (All times are UTC )

 




Post new topic Reply to topic  [ 9 posts ] 
Author Message
Posted: Fri May 18, 2007 11:46 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Nov 04, 2006 6:17 am
Posts: 20
Apparently there are a lot of people wondering how to sort the contacts list alphabetically...

This is pretty simple with a small php hack, in fact a single word. When in comes to sorting, you are always better to retrieve the results sorted from mysql rather than trying to sort the array (simple if its a 1d array, otherwise inefficient)..

open yoursite.com\components\com_contact\contact.php

I'm using 1.0.12 and its line 122 that you want to go to or search for the following code:

115 if ( $catid ) {
116 // url links info for category
117 $query = "SELECT *"
118 . "\n FROM #__contact_details"
119 . "\n WHERE catid = " . (int) $catid
120 . "\n AND published =1"
121 . "\n AND access <= " . (int) $my->gid
122 . "\n ORDER BY name"
123 ;
124 $database->setQuery( $query );
125 $rows = $database->loadObjectList();

change line 122 above from:

ORDER BY ordering

to:

ORDER BY name

voila!
you now have the contacts list ordered by the name of the contact alphabetically.

Of course, this will ignore the ordering you have done in the backend by using the arrows.

This can be applied to any field by changing the ordering to another field name like position or whatever....

to get a list of the field names stored in the array use var_dum($array) somewhere on your form....


Last edited by humvee on Sat May 19, 2007 12:34 pm, edited 1 time in total.

Top
  E-mail  
 
Posted: Fri May 18, 2007 6:02 pm 
Joomla! Guru
Joomla! Guru
Offline

Joined: Thu Oct 05, 2006 12:13 am
Posts: 800
Hi takara,

This is a good example of core hack to publish at Custom Joomla! Development board => Core Hacks and Patches

That is the proper place for this type of posts, and i'm sure that there it will be very useful to many users.

Thanks

Leandro

_________________
"The skill of writing is to create a context in which other people can think" - Edwin Schlossberg.


Top
  E-mail  
 
Posted: Mon Mar 31, 2008 10:07 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Feb 29, 2008 6:07 pm
Posts: 6
Any way to do this for 1.5?


Top
  E-mail  
 
Posted: Tue Apr 08, 2008 5:49 pm 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Tue Apr 08, 2008 5:21 pm
Posts: 1
alam813 wrote:
Any way to do this for 1.5?


I did this, it seems to work:
In /components/com_contact/views/category/view.html.php

Line 41: $filter_order = JRequest::getVar('filter_order', 'cc.ordering', '', 'cmd');

Change 'cc.ordering' to the field you want to be ordered by. I used alias instead of name. Whenever I add a contact, I set alias to be lastname-firstname, this way it will sort alphabetically by last name. So my line 41 looks like:

Line 41: $filter_order = JRequest::getVar('filter_order', 'alias', '', 'cmd');

Good luck!


Top
  E-mail  
 
Posted: Tue Apr 08, 2008 9:03 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Feb 29, 2008 6:07 pm
Posts: 6
Worked like a charm, thanks!


Top
  E-mail  
 
Posted: Mon Apr 14, 2008 7:36 am 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Mon Oct 31, 2005 1:01 pm
Posts: 144
many thanks
btw, I have also been using the contactinfo module to display the contact info and it's brilliant


Top
   
 
Posted: Mon May 05, 2008 2:43 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Feb 23, 2008 11:20 pm
Posts: 23
Just want to say thanks...I was just looking for this. Maybe something that should be included as a core option.


Top
  E-mail  
 
Posted: Fri Jul 10, 2009 9:13 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri May 23, 2008 8:01 pm
Posts: 9
how can i do this to sort by multiple fields eg. ORDER BY con_position, name

I used the code like this, but it did not work for me:

$filter_order = JRequest::getVar('filter_order', 'con_position, name', '', 'cmd');


Any ideas? Thanks


Top
  E-mail  
 
Posted: Mon Aug 03, 2009 7:40 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Tue Feb 17, 2009 2:19 pm
Posts: 6
Works great indeed! Thanks a lot.

Yet I have one more question. Is there a way to save the edited view.html.php file in my template folder, along with other template overrides?


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group