Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function insert_interests($uid, $interests) {
  2. /* first, we'll delete any entries this user already has in the table */
  3. purge_lookup("jss_users_interests_table", $uid);
  4. /* now create the sql insert query */
  5. global $db;
  6. $db->query(create_checkbox_query($interests, "jss_users_interests_table", $uid));
  7. }
  8. /* helper function for insert_interests(). removes all rows in $table with $uid */
  9. function purge_lookup($table, $uid) {
  10. global $db;
  11. $db->query("DELETE FROM $table WHERE users_id = '".$db->escape($uid)."'");
  12. }
  13. /* helper function for insert_interests(). generates the actual SQL query */
  14. function create_checkbox_query($arr, $table, $uid) {
  15. $q = "INSERT INTO $table (users_id, subcategories_id) VALUES";
  16. foreach ($arr as $check) {
  17. $q .= " ( '$uid' , $check )" . ",";
  18. }
  19. /* remove the last comma and return */
  20. return substr($q, 0, -1);
  21. }`
  22.  
  23. INSERT INTO jss_info_requests_table
  24. (users_id, provider_id, subcategories_id)
  25. SELECT a.users_id,
  26. b.provider_id, b.subcategories_id FROM
  27. jss_users_interests_table a,
  28. jss_providers_assignments_table b
  29. WHERE a.subcategories_id =
  30. b.subcategories_id AND a.users_id =
  31. [USERID]
Add Comment
Please, Sign In to add comment