Page 1 of 1

Show latest comment from table Comment

Posted: 2019-06-29 11:18
by tminh
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

Re: Show latest comment from table Comment

Posted: 2019-06-29 11:45
by pbottcher
Hi,

what is the identifier to retrieve the latest comment?

Re: Show latest comment from table Comment

Posted: 2019-06-30 10:10
by onoehring
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

Re: Show latest comment from table Comment

Posted: 2019-06-30 10:19
by jsetzer
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

Re: Show latest comment from table Comment

Posted: 2019-06-30 10:26
by onoehring
Hi Jan,

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

Re: Show latest comment from table Comment

Posted: 2019-07-18 14:54
by tminh
tks you i'm trying

Re: Show latest comment from table Comment

Posted: 2019-07-18 14:56
by tminh
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 ) <<<<

Re: Show latest comment from table Comment

Posted: 2019-07-18 14:57
by tminh
table_view.php table_dml.php

Re: Show latest comment from table Comment

Posted: 2019-07-18 16:19
by pbottcher
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.