Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure If I fully understand your question, but What I'm getting is this:</p> <pre><code>&lt;?php //this is placed after connecting to and selecting your mysql database $query = "SELECT * FROM `stories` WHERE `showing` = 0"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { //count how many votes we have $query2 = "SELECT * FROM `votes` WHERE `item_name` = '".$row['id']."'"; //assuming item_name in votes = id in stories $result2 = mysql_query($query2); $ourCount = 0; while($row2 = mysql_fetch_array($result2)) { $ourCount = $ourCount + $row['vote_value'];//assuming vote value is where your +1 or -1 or whatever value is stored. } if($ourCount &gt;= 10) { //I'm assuming, you want to show it if the votes equal or are greater than 10... $query3 = "UPDATE `stories` SET `showing` = 1 WHERE `id` = '".$row['id']."'"; mysql_query($query); } else if($ourCount &lt;= -10) { //again i'm assuming you want to set 2 where votes is equal to or less than -10 $query3 = "UPDATE `stories` SET `showing` = 2 WHERE `id` = '".$row['id']."'"; mysql_query($query); } else { //you can really take this part out as it's redundant, but i'm placing it here anyways. $query3 = "UPDATE `stories` SET `showing` = 0 WHERE `id` = '".$row['id']."'"; mysql_query($query); } } ?&gt; </code></pre> <p>What this does is gets all rows from "stories" where "showing" = 0. Then it searches votes for any item_name with the value of the story id. From there, it adds the "item_value" which can be negative for down votes. It then figures out if the end result is greater than equal to 10, less than equal to -10, or (-10,10). It then executes the corresponding query to set the showing to 1, 2, and 0 respectively.</p> <p>Hope I understood your question properly!</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. 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