Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 4.50 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP update MySQL looping
  2. $userID = 1;
  3. $value = 1;
  4. $contestID = 1737;
  5. if (($userID > 0) && ($contestID > 0) && ($value < 2)){
  6.     $query = mysql_query("SELECT * FROM userContests WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
  7.  
  8.     $getfreq = mysql_query("
  9.             SELECT wp_term_relationships.term_taxonomy_id
  10.             FROM wp_term_relationships
  11.             WHERE wp_term_relationships.object_id = $contestID
  12.         ");
  13.  
  14.     while ($row = mysql_fetch_assoc($getfreq)) {
  15.         if ($value == 1){ // If the contest is liked
  16.             if (mysql_num_rows($query) > 0) {  //if a value matching the userID and contest ID already exists in database
  17.                  if ($row[term_taxonomy_id] == 345) { // if Daily entry, update the row with reminder date
  18.                     echo "1";
  19.                     mysql_query("UPDATE userContests SET value='$value', reminder= DATE_ADD(CURDATE(),INTERVAL 1 DAY) WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
  20.                     $frequency = 'Daily';
  21.                 } else { // if anything other than above, insert the row with current date
  22.                     echo "2";
  23.                     mysql_query("UPDATE userContests SET value='$value', reminder= CURDATE() WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
  24.                 }
  25.             } else { // if there is no previous row in database matching userID and contestID
  26.                 if ($row[term_taxonomy_id] == 345) { // if Daily entry, insert the row with reminder date
  27.                     echo "3";
  28.                     mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', 'DATE_ADD(CURDATE(),INTERVAL 1 DAY)') ") or die(mysql_error());
  29.                 } else { // if anything other than above, insert the row with current date
  30.                     echo "4";
  31.                     mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error());
  32.                 }
  33.             }
  34.         } else if ($value == 0){ // if the value is disliked
  35.             if (mysql_num_rows($query) > 0) {  //if a value matching the userID and contest ID already exists in database, simply update the row without reminder
  36.                 echo "5";
  37.                 mysql_query("UPDATE userContests SET value='$value' WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
  38.             } else { // if there is no previous row in database matching userID and contestID, simply insert the row without reminder
  39.             echo "6";
  40.                 mysql_query("INSERT INTO userContests (userID, contestID, value) VALUES ('$userID', '$contestID', '$value') ") or die(mysql_error());
  41.             }
  42.         }
  43.     }
  44. }
  45.        
  46. if ($row[term_taxonomy_id] == 345) { // if Daily entry, insert the row with reminder date
  47.                 echo "3";
  48.                 mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', 'DATE_ADD(CURDATE(),INTERVAL 1 DAY)') ") or die(mysql_error());
  49.             } else { // if anything other than above, insert the row with current date
  50.                 echo "4";
  51.                 mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error());
  52.             }
  53.        
  54. mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error());
  55.        
  56. $getfreq = mysql_query("
  57.         SELECT COUNT(taxonomy_id) AS freq
  58.         FROM wp_term_relationships
  59.         WHERE wp_term_relationships.object_id = $contestID
  60.          AND wp_term_relationshis.taxonomy_id = 345
  61.     ");    
  62.  
  63. $data = mysql_fetch_assoc($getfreq);
  64.  
  65. if ($data['freq'] > 1) {
  66.     //do something
  67. } else {
  68.     //do something else
  69. }
  70.        
  71. $getfreq = mysql_query("
  72.         SELECT DISTINCT term_taxonomy_id
  73.         FROM wp_term_relationships
  74.         WHERE wp_term_relationships.object_id = $contestID
  75.     ");    
  76.  
  77. while ($row = mysql_fetch_assoc($getfreq)) {
  78.     $taxonomy_id = $row[term_taxonomy_id];
  79.     $seen[$taxonomy_id] = 1;
  80. }
  81.  
  82. if ($seen[334]) {
  83.    //something
  84. } else if ($seen[456]) {
  85.    //something else
  86. } else {
  87.    //last branch
  88. }
  89.        
  90. $resultSet= mysql_get_assoc($getfreq);
  91.  
  92. if ( array_search(345,$resultSet) !== false )
  93. {
  94.  
  95. # - 345 Is here!!! -
  96.  
  97. //do what you gotta do...
  98.  
  99.  
  100. }
  101.  
  102. else
  103. {
  104.  
  105. # - 345 is not in $resultSet -
  106.  
  107. //do something else here
  108.  
  109. }