SHARE
TWEET

Untitled

a guest Feb 21st, 2020 154 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- #####################################################
  2. -- [ ADD DATA TO DB ]
  3.  
  4. -- SELECT DATABASE
  5. USE mydb;
  6.  
  7. -- GET USER ID
  8. SELECT @userID := 1408;
  9.  
  10. -- ADD USER
  11. INSERT INTO users (user_id, name)
  12.     VALUES (@userID, 'Vasia');
  13.  
  14. -- ADD QUESTION
  15. INSERT INTO questions (text)
  16.     VALUES ('Ты охуел?');
  17.  
  18. -- GET QUESTION ID
  19. SELECT @questionID := LAST_INSERT_ID();
  20.  
  21. -- INSERT ANSWER
  22. INSERT INTO answers (text)
  23.     VALUE ('Да.');
  24.  
  25. -- GET ANSWER ID
  26. SELECT @answerID := LAST_INSERT_ID();
  27.  
  28. -- LINK THE QUESTION AND THE ANSWER
  29. INSERT INTO conn_quest_ans (question_id, answer_id, user_id)
  30.     VALUES (@questionID, @answerID, @userID);
  31.    
  32. -- ############################################################
  33. -- [ GET DATA FROM DB ]
  34.  
  35. -- GET USER ID
  36. SELECT @userID := 1408;
  37.  
  38. -- GET USER'S COINS AND EXP
  39. SELECT @user_coins := coins, @user_exp := exp FROM users
  40.     WHERE user_id = @userID;
  41.  
  42. -- INCREMENT COINS AND EXP
  43. UPDATE users SET coins = @user_coins + 1, exp = @user_exp + 1
  44.     WHERE user_id = @userID;
  45.    
  46. -- SEARCH THE QUESTION
  47. -- TRY REGEXP NEXT TIME !!!
  48. SELECT @questionID := question_id FROM questions
  49.     WHERE text = 'Ты охуел?';
  50.    
  51. -- GET ALL RELATED ANSWERS' IDs
  52. SELECT @answID := answer_id, @relatedUserID := user_id FROM conn_quest_ans
  53.     WHERE question_id IN (@questionID);
  54.  
  55. -- GET ALL ANDSWERS
  56. SELECT text FROM answers
  57.     WHERE answer_id = @answID
  58.    
  59. -- @relatedUserID might be used to choose the best answer
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top