Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think you have an error in the loop. </p> <p>You just never update any of the variables, that you have in the inserting SQL.</p> <p>I mean - you say you have 5 values in $getfreq, the third one is 345 and therefore the branch with "3" will happen, in all the other cases, the branch with "4" will happen. None of the other variables are changed, ever.</p> <p>You get into this branch</p> <pre><code> 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()); } </code></pre> <p>In the third case, it gets into the "3" branch and is inserted.</p> <p>However, in all the other cases, this line is executed</p> <pre><code> mysql_query("INSERT INTO userContests (userID, contestID, value, reminder) VALUES ('$userID', '$contestID', '$value', CURDATE()) ") or die(mysql_error()); </code></pre> <p>because you have it in <code>else</code> branch.</p> <p>If you don't want to do the loop at all and just want to check once, you will have to do something like this.</p> <pre><code>$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'] &gt; 1) { //do something } else { //do something else } </code></pre> <p>I hope I wrote it correctly since I am doig it from top of my head :)</p> <p>If you want to check for more than one value, try this:</p> <pre><code>$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 } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload