How to order displayed Tables by date -- HELP Me Please?

mukwano 09 Apr, 2009
Hi there gurus,
I am a newbie at this:

I created a form which is used by the user to enter Data (both of text and of Date Type) into the Database using Chrono Forms.

I have been able to extract and display this data in table format and with the help of ChronoConnectivity. The tables display the Date of Entry; and A description.

I would like to display these tables ordered by date (i.e. the most recent table ()entry) should be listed first; and the older tables listed after.

Is this possible with ChronoConnectivity? And if so, how?

Thanks

Mukwano
GreyHead 09 Apr, 2009
Hi Mukwano,

I'm not sure, you could try adding ORDER BY `field_name` in the WHERE box (after any where code).

Bob
mukwano 09 Apr, 2009
Excellent. That worked very well.

Thanks a bunch ๐Ÿ˜€
tidusx18 10 Apr, 2009
Hi,

I was wondering if aside from the ORDER BY statement, if there is a way for a user to sort the table displayed by Chrono Connectivity by his/her preference in the front end?

Thanks!
GreyHead 10 Apr, 2009
Hi tidusx18,

I don't think so - maybe in a future version. Though possibly you could code in sorting column headers . . .

Bob
tidusx18 10 Apr, 2009
Well, before I posted this I tried following this website >>> http://kryogenix.org/code/browser/sorttable/ and I saw that the column headers in the front end had little sorting arrows when I clicked on them, but nothing was being sorted. Is there a way to use what that website shows?
tidusx18 15 Apr, 2009
Any ideas...anyone...? ๐Ÿคจ ๐Ÿ˜€
GreyHead 15 Apr, 2009
Hi tidusx18,

The code to do this exists in Joomla - but enabling it in ChronoConnectivity needs quite a it of work on the core code as it actually relies on new database calls to get the re-sorted data.

Bob
tidusx18 15 Apr, 2009
Oh, ok. Hopefully, sorting will be included in the next CC release ๐Ÿ™‚ .
tidusx18 23 Apr, 2009
Hi Bob,

I was looking at Chrono Connectivity and can't the same code that is used to sort columns in the admin records display area be used in the front end to sort the record by column names? ๐Ÿ˜ฒ

...hmm...๐Ÿ˜›
purple knight 24 Apr, 2009
My 'where sql' code now looks like this
<?php
$search_array = array('<text_14', 'select_2'); 
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}?>




May I know where should I insert the code?

Hi Mukwano,

I'm not sure, you could try adding ORDER BY `field_name` in the WHERE box (after any where code).

Bob



Thank you ๐Ÿ˜€
tidusx18 24 Apr, 2009
You can insert the ORDER BY SQL statement at the bottom. Thats what I did and it worked fine. ๐Ÿ˜€

Daniel-
GreyHead 24 Apr, 2009
Hi Purple Knight,

Exactly as Daniel said - at the end after the 'where' code
if ( !empty($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}
echo " ORDER BY `some_field` ";
?>
Make sure to leave a space before so that it is separated from the end of the previous code.

Bob
infobuster 24 Apr, 2009
Just in case anyone needs any further help with this i've had a play around and got the headers to sort by either ascending or descending order

this is what i put in the WHERE SQL box

ORDER BY cf_id DESC

by adding this to the WHERE SQL box it will put the latest entry to the top

and by putting

ORDER BY cf_id ASC it will put the oldest entery to the top

hope this helps someone someday
purple knight 25 Apr, 2009
Awesome! Thanks a lot, Daniel, Bob & Infobuster, now it works well! ๐Ÿ˜€
GreyHead 25 Apr, 2009
Hi simonjoomla,

Yes, the same code should work in both versions.

The critical piece to do the sorting is
<?php
echo " ORDER BY cf_id DESC ";
?>
This needs to be in the 'Where' box - after any other record selection code you may have.

Bob
simonjoomla 25 Apr, 2009
Thank you very much. But may I know which file should I place the code you mentioned. e.g components\com_chronocomments\.... I don't really know which file you all are discussing to add the code to. thanks.
GreyHead 25 Apr, 2009
Hi Simonjoomla,

This is the ChronoConnectivity area of the Forums and the code goes in the ChronoConnectivity Where box.

Bob
simonjoomla 27 Apr, 2009
Got it! Thanks Bob. ๐Ÿ˜€
dgraham 11 Jan, 2010
Warning: Invalid argument supplied for foreach() 


Can't seem to get it. I'm not all that good @ constructing code. I just need the single table chronoforms_addcode to sort its frontend results by cf_id DESC and the above is the error i get.
I've have the results ordered by cf_id... can't seem to SORT them DESC

scratching head here.
GreyHead 11 Jan, 2010
Hi dgraham,

IIRC the current version of ChronoForms has an ORDER BY box, I think you can just add `cf_id` DESC in there. (I'm never certain if you need the 'ORDER BY' as well but I think not.)

Bob
dgraham 11 Jan, 2010
That was it m8... thank you! no need to put the ORDER BY.
Also these both worked
cf_id DESC
`cf_id` DESC

if it was a snake it would have bit me. Cheers!
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger