This topic is locked

Add count to master table

2/5/2015 12:12:34 AM
PHPRunner General questions
P
pelican author

I am new to this and trying to add 1 to a count when child table list is loaded as below:
Master table name - sf_discussion

ID - primary

title

v_count - is the count

date

User
Child table name - sf_comment

id

discussion_ID - linked to (master) ID

comment

time
I have added in JavaScript OnLoad event

UPDATE sf_discussions

SET v_count = v_count + 1

WHERE ID = '$discussion_id'
Can anyone please advise me am I adding this to the correct Event and what I am doing wrong in the command.
Thanks

P
pelican author 2/7/2015

I know this is possibly a very simple issue, but I have searched for a solution and can not find anything that will work tried lots of variations don't even know if i am putting it in the correct place .
If anyone can advise me I would be very grateful.

Sergey Kornilov admin 2/9/2015

It's very difficult to understand what exactly you trying to achieve. If you are only trying to add one to one of fields - it's not clear how child table is relevant here.
If you only need to add 1 to any field - you can do that in SQL Query:

select ID,

title,

v_count,

v_count+1 as new_count,

date,

User

from ...
P
pelican author 2/9/2015

Sorry I will try to explain better what i am trying to do.
when a list view is displayed (from a child table) I want to add 1 to the relevant record (in the master table).
master table(example) sf_discussion
id ----- title ----- V_count

1 ----- red ----- 23

2 ----- blue ----- 12

3 ----- green ----- 33
so if the operator click on "blue" this will display the list view (child table) for blue comments
child table(example)sf_comment
id ----- discussion ----- Comments

1 ----- blue ----- this is good

2 ----- blue ----- more

3 ----- blue ----- and more
so when this Comments list view is displayed the V_count for blue (in master table) is increased by 1
id ----- title ----- V_count

1 ----- red ----- 23

2 ----- blue ----- 13 (increased by 1)

3 ----- green ----- 33
I hope this is clearer on what i am trying to do.
Thanks