Note that there are some explanatory texts on larger screens.

plurals
  1. POSet a cron job to update article information depending on its vote values
    primarykey
    data
    text
    <p>I want to set a cron job that will execute every 15 minutes. Before going into deep description of these query I'll explain how my database works.</p> <p>I have 2 tables '<strong>stories</strong>' and '<strong>votes</strong>'. All information about article like title, category etc. is stored in the '<strong>stories</strong>' table. It's not a big surprise that all the votes related to article are stored in a '<strong>votes</strong>' table. In the votes table there is a field named '<strong>item_name</strong>' which corespondents to the '<strong>id</strong>' of article that is in 'stories' table. Finally, in '<strong>stories</strong>' table I have a field named '<strong>showing</strong>' which is by default set to 0. And I want to change it to different values depending on how many votes article has, but more about it latter.</p> <p>Here is a structure of my database:</p> <p><strong>Stories table</strong></p> <p><img src="https://i.stack.imgur.com/NDf6L.jpg" alt="enter image description here"></p> <hr> <p><strong>Votes table</strong></p> <p><img src="https://i.stack.imgur.com/oh9J0.jpg" alt="enter image description here"></p> <hr> <p>Ok now when I cleared database structure lets get down to my question. I need a query that would look at all articles where showing=0 and sum up votes that corespondent to a particular article. If sum of votes = 10 than set showing=1 if sum of votes = -10 than set showing=2. I don't know how such query would look, I really don't :/ So could anyone suggest a solution please?</p> <p><strong>Addition:</strong> I asked similar question before and some people suggested trigger's or updating database each time a vote is cast. But I would rather check it every 15 min with cron job. )))</p> <p><strong>EDIT:</strong> Just to give you more understanding of how it works )))</p> <p>For example this row from 'stories' table:</p> <p><strong>id|</strong> 12 <br> <strong>st_auth |</strong> author name <br> <strong>st_date |</strong> story date <br> <strong>st_title|</strong> story title <br> <strong>st_category|</strong> story category <br> <strong>st_body|</strong> story body <br> <strong>showing|</strong> 0 for pending, 1 for approved and 2 for unapproved</p> <p>Co responds to this one from ;votes' table:</p> <p><strong>id|</strong> 83 <br> <strong>item_name|</strong> 12 (id of article) <br> <strong>vote_value|</strong> 1 for upvote -1 for downvote etc...</p>
    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.
 

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