Buy Now
Sign in

How to select 7 latest record from a table

lf14web , June 13 at 15:40
L
lf14web
In a table with thousands records, I need to select the latest 7 items order by ASC.​
​In the table option I found the order by, but extract the first 7 records with ASC or the latest 7 with DESC but with inverse order.
Regards
Emanuele
GreyHead
Hi Emanuele,
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
L
lf14web
Hi Bob!
thank you for your reply.
Yes with sql code I know how to do that. But I don't know ho I can replicate that with Read Data or if there are a best way in chronoform6 to obtain this result.
Do you have other suggest?
Thanks
Emanuele
GreyHead
Hi Emanuele,
Please check the Writing conditions section at page 24 of the CFv6 manual - I think that you can write a custom query if needed.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
L
lf14web
I think that a cusom query its a good way, but I don't now how to insert in chronoforms6.​
​Please could you to give me an example?​
​Thanks!
L
lf14web
Bob,
please could you to give me an example how I can create a custom query?
Thanks a lot!
Emanuele
healyhatman
Just do read data, sorted by created date, then use a PHP action together the 7 items you want from the array
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
L
lf14web
Hi healyhatman,
since the table contains a lot of thousand of record, maybe the best solution is get the seven records with DESC order by and use the array_reverse functions.​
​​
​But I do not understand how I can do that.​
​I've read the manual, but in general I have many difficulties to manage the array data with chronoforms 6, with cf5 is more simple.​
​​
​Thanks
healyhatman
Then use the paging option and set the record count to 7
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
L
lf14web
Yes I do that but I've the latest record how first in the array.
11359
11358
11357
...
I need ro reverse the array to have the record in right order
...
11357
11358
11359
[read_data4] => Array
(
[log] => Array
(
[0] => SELECT COUNT(`extralaghi`.`aid`) AS `extralaghi.count` FROM `u53uf_chronoforms_data_rilievi-idrometrici-laghi` AS `extralaghi`;
[1] => SELECT `extralaghi`.`aid` AS `extralaghi.aid`, `extralaghi`.`user_id` AS `extralaghi.user_id`, `extralaghi`.`created` AS `extralaghi.created`, `extralaghi`.`modified` AS `extralaghi.modified`, `extralaghi`.`data` AS `extralaghi.data`, `extralaghi`.`lago` AS `extralaghi.lago`, `extralaghi`.`idro` AS `extralaghi.idro`, `extralaghi`.`note` AS `extralaghi.note` FROM `u53uf_chronoforms_data_rilievi-idrometrici-laghi` AS `extralaghi` ORDER BY `extralaghi.aid` DESC LIMIT 10;
)

[var] => Array
(
[0] => Array
(
[extralaghi] => Array
(
[aid] => 11359
[user_id] => 0
[created] => 2018-06-15 15:25:43
[data] => 15/06/2018
[lago] => Lago di Como
[idro] => 200
[note] => nota qualsiasi "dqtq"
)

)

[1] => Array
(
[extralaghi] => Array
(
[aid] => 11358
[user_id] => 0
[created] => 2018-06-14 22:37:00
[data] => 15/06/2018
[lago] => Lago di Iseo
[idro] => 52
[note] => dsfads sadf adsf asdf
)

)

[2] => Array
(
[extralaghi] => Array
(
[aid] => 11357
[user_id] => 0
[created] => 2018-06-15 14:55:24
[data] => 15/06/2018
[lago] => Lago di Como
[idro] => 100
[note] => dfas dsfads dsfa sd
)

)

[3] => Array
(
[extralaghi] => Array
(
[aid] => 11356
[user_id] => 0
[created] => 2018-06-14 22:25:29
[data] => 14/06/2018
[lago] => Lago di Como
[idro] => 24
[note] => dsafsd dsfasd asdf 3
)

)

[4] => Array
(
[extralaghi] => Array
(
[aid] => 11355
[user_id] => 0
[created] => 2018-06-14 22:37:15
[data] => 14/06/2018
[lago] => Lago di Iseo
[idro] => 22
[note] => dfsa
)

)

[5] => Array
(
[extralaghi] => Array
(
[aid] => 11354
[user_id] => 0
[created] => 2018-06-14 22:37:25
[data] => 13/06/2018
[lago] => Lago di Iseo
[idro] => 180
[note] => sdafsd sdafae dsfa
)

)

[6] => Array
(
[extralaghi] => Array
(
[aid] => 11353
[user_id] => 0
[created] => 2018-06-14 22:37:38
[data] => 13/06/2018
[lago] => Lago di Como
[idro] => 200
[note] => dsafsdfsafds
)

)

[7] => Array
(
[extralaghi] => Array
(
[aid] => 11352
[user_id] => 0
[created] => 2018-06-14 22:37:45
[data] => 12/06/2018
[lago] => Lago di Como
[idro] => 200
[note] => ddsfsdf
)

)

[8] => Array
(
[extralaghi] => Array
(
[aid] => 11351
[user_id] => 0
[created] => 2018-06-14 22:09:14
[data] => 14/06/2018
[lago] => Lago di Como
[idro] => 200
[note] => dfsa
)

)

[9] => Array
(
[extralaghi] => Array
(
[aid] => 11350
[user_id] => 0
[created] => 2018-06-14 21:59:34
[data] =>
[lago] =>
[idro] =>
[note] =>
)

)

)

)
healyhatman
Get the value array in PHP with $this->get("read_data4", "")
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
L
lf14web
Ok Thank You!
Work fine with this code into PHP module
$revextra = $this->get("read_data4", "");​
​return array_reverse($revextra);
Emanuele