PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] creating a trigger in php-my-admin

 January 20, 2022     database, mysql, phpmyadmin, sql     No comments   

Issue

i would like to create a trigger using the phpmyadmin "add trigger" option. The Trigger should run AFTER every INSERT in table comments that takes the highest "number of comments" (nc in DB) from the table "POST" and takes the "ID" and the "question" of that row and puts it in the "top_questions" table

Update1: i want the top 5 records with the 5 highest "number of comments" sorted descendingly to be put into the table Top Questions

Post Table: post table

Top Questions Table:top_questions table

MCO stands for "most commented on" and that's where the question needs to be taken from post and put in

Comment Table: comment table

update2: at this point i'm wondering should i make it as a trigger, view, or materialized view? (i would still prefer it as a trigger)


Solution

you can put it by selecting after insert command

BEGIN

INSERT INTO top_question(MCO,PID)
SELECT ID,P_ID FROM `comment_tbl` GROUP BY P_ID order by COUNT(*) DESC LIMIT 10    

END

just put this lines in phpmyadmin in trigger (select after insret in commaent table )



Answered By - kiamoz
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing