Show latest comment from table Comment

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
tminh
Posts: 22
Joined: 2019-05-23 02:26

Show latest comment from table Comment

Post by tminh » 2019-06-29 11:18

I have 2 table :

table 1 : property
- ID
- Property Name
- LandLot
- Latest Comment ( function column, this will pull onnly 1 latest comment in table 2 )

Table 2 : property_comment
- id
- comment
- property => look up to table 1 - ID

How do i show Latest Comment ( function column, this will pull onnly 1 latest comment in table 2 )

thanks

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 611
Joined: 2018-04-01 10:12

Re: Show latest comment from table Comment

Post by pböttcher » 2019-06-29 11:45

Hi,

what is the identifier to retrieve the latest comment?

onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 298
Joined: 2019-05-21 22:42
Contact:

Re: Show latest comment from table Comment

Post by onoehring » 2019-06-30 10:10

Hi tmih,

I do not really understand what you are trying to do. I suppose to have a "latest" comment, you would also need a date/time identifier. If you have a field with that timestamp, you can so something like (code not tested)

Code: Select all

select * from property_comment order by yourtimestampfield DESC limit 1
Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 257
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Show latest comment from table Comment

Post by jsetzer » 2019-06-30 10:19

Hi,

There is no need for an additional column in this scenario. You can use the existing auto-increment id-column. The greater the id, the newer the record. So you'll have so sort DESCENDING.

Code: Select all

SELECT * 
FROM `comments` 
WHERE `property_id` = 1
ORDER BY `id` DESC 
LIMIT 1
But if you need for example the last modified comment, you should add a column "modified_on" (datetime), for example as Olaf has suggested. You can use the AppGini built-in default value "<%%editingDateTime%%>" for example

Best,
Jan

onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 298
Joined: 2019-05-21 22:42
Contact:

Re: Show latest comment from table Comment

Post by onoehring » 2019-06-30 10:26

Hi Jan,

I agree, but using a timestamp would enable to edit old records (and make an existing comment "newer").
Olaf

tminh
Posts: 22
Joined: 2019-05-23 02:26

Re: Show latest comment from table Comment

Post by tminh » 2019-07-18 14:54

tks you i'm trying

tminh
Posts: 22
Joined: 2019-05-23 02:26

Re: Show latest comment from table Comment

Post by tminh » 2019-07-18 14:56

thank you, i know sql code but how do i add it to table view ?? thanks,can you give me an example

table 1 : property
- ID
- Property Name
- LandLot
- Latest Comment ( function column, this will pull onnly 1 latest comment in table 2 ) <<<<

tminh
Posts: 22
Joined: 2019-05-23 02:26

Re: Show latest comment from table Comment

Post by tminh » 2019-07-18 14:57

table_view.php table_dml.php

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 611
Joined: 2018-04-01 10:12

Re: Show latest comment from table Comment

Post by pböttcher » 2019-07-18 16:19

Hi,

in the hooks/property_comment.php (Assuming, property_comment is the table you are using for the comments)

add to the function property_comment_after_insert
and also to the function property_comment_after_update

Code: Select all

sqlvalue("update property set `Latest Comment` = '".$data['comment']."'  where property.ID = '".$data['property']."'");
This shall put the latest comment, or the latest edited comment to your poperty table.

Post Reply