- PHP update MySQL looping
- $userID = 1;
- $value = 1;
- $contestID = 1737;
- if (($userID > 0) && ($contestID > 0) && ($value < 2)){
- $query = mysql_query("SELECT * FROM userContests WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
- $getfreq = mysql_query("
- SELECT wp_term_relationships.term_taxonomy_id
- FROM wp_term_relationships
- WHERE wp_term_relationships.object_id = $contestID
- ");
- while ($row = mysql_fetch_assoc($getfreq)) {
- if ($value == 1){ // If the contest is liked
- if (mysql_num_rows($query) > 0) { //if a value matching the userID and contest ID already exists in database
- if ($row[term_taxonomy_id] == 345) { // if Daily entry, update the row with reminder date
- echo "1";
- mysql_query("UPDATE userContests SET value='$value', reminder= DATE_ADD(CURDATE(),INTERVAL 1 DAY) WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
- $frequency = 'Daily';
- } else { // if anything other than above, insert the row with current date
- echo "2";
- mysql_query("UPDATE userContests SET value='$value', reminder= CURDATE() WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
- }
- } else { // if there is no previous row in database matching userID and contestID
- if ($row[term_taxonomy_id] == 345) { // if Daily entry, insert the row with reminder date
- echo "3";
- mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', 'DATE_ADD(CURDATE(),INTERVAL 1 DAY)') ") or die(mysql_error());
- } else { // if anything other than above, insert the row with current date
- echo "4";
- mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error());
- }
- }
- } else if ($value == 0){ // if the value is disliked
- 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
- echo "5";
- mysql_query("UPDATE userContests SET value='$value' WHERE userID='$userID' AND contestID='$contestID';") or die(mysql_error());
- } else { // if there is no previous row in database matching userID and contestID, simply insert the row without reminder
- echo "6";
- mysql_query("INSERT INTO userContests (userID, contestID, value) VALUES ('$userID', '$contestID', '$value') ") or die(mysql_error());
- }
- }
- }
- }
- if ($row[term_taxonomy_id] == 345) { // if Daily entry, insert the row with reminder date
- echo "3";
- mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', 'DATE_ADD(CURDATE(),INTERVAL 1 DAY)') ") or die(mysql_error());
- } else { // if anything other than above, insert the row with current date
- echo "4";
- mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error());
- }
- mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error());
- $getfreq = mysql_query("
- SELECT COUNT(taxonomy_id) AS freq
- FROM wp_term_relationships
- WHERE wp_term_relationships.object_id = $contestID
- AND wp_term_relationshis.taxonomy_id = 345
- ");
- $data = mysql_fetch_assoc($getfreq);
- if ($data['freq'] > 1) {
- //do something
- } else {
- //do something else
- }
- $getfreq = mysql_query("
- SELECT DISTINCT term_taxonomy_id
- FROM wp_term_relationships
- WHERE wp_term_relationships.object_id = $contestID
- ");
- while ($row = mysql_fetch_assoc($getfreq)) {
- $taxonomy_id = $row[term_taxonomy_id];
- $seen[$taxonomy_id] = 1;
- }
- if ($seen[334]) {
- //something
- } else if ($seen[456]) {
- //something else
- } else {
- //last branch
- }
- $resultSet= mysql_get_assoc($getfreq);
- if ( array_search(345,$resultSet) !== false )
- {
- # - 345 Is here!!! -
- //do what you gotta do...
- }
- else
- {
- # - 345 is not in $resultSet -
- //do something else here
- }