Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6987743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:58:43+00:00 2026-05-27T18:58:43+00:00

I want to set a cron job that will execute every 15 minutes. Before

  • 0

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.

I have 2 tables ‘stories‘ and ‘votes‘. All information about article like title, category etc. is stored in the ‘stories‘ table. It’s not a big surprise that all the votes related to article are stored in a ‘votes‘ table. In the votes table there is a field named ‘item_name‘ which corespondents to the ‘id‘ of article that is in ‘stories’ table. Finally, in ‘stories‘ table I have a field named ‘showing‘ 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.

Here is a structure of my database:

Stories table

enter image description here


Votes table

enter image description here


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?

Addition: 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. )))

EDIT: Just to give you more understanding of how it works )))

For example this row from ‘stories’ table:

id| 12
st_auth | author name
st_date | story date
st_title| story title
st_category| story category
st_body| story body
showing| 0 for pending, 1 for approved and 2 for unapproved

Co responds to this one from ;votes’ table:

id| 83
item_name| 12 (id of article)
vote_value| 1 for upvote -1 for downvote
etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:58:44+00:00Added an answer on May 27, 2026 at 6:58 pm
    select sum(vt.vote_value), vt.item_name
    from Votes vt
    join stories st on st.id = vt.item_name
    and st.showing = 0
    group by vt.item_name
    

    This should give you all the articles with showing 0 and total vote value. After that you can process them row by row and update voting if needed.

    Added:
    I am not a PHP programmer, I mostly do PERL, but I guess it has to be something like this:

    <?php 
        $query = "select sum(vt.vote_value) as vote_value, vt.item_name from Votes vt join stories st on st.id = vt.item_name and st.showing = 0 group by vt.item_name";
        $result = mysql_query($query); 
        while($row = mysql_fetch_array($result))
        {
            if($row['vote_value'] > 9) {
                $showing = 1;
            }
            else if($row['vote_value'] < -9) {
                $showing = 2;
            }
            else {
                $showing = 0;
            }
            $query2 = "UPDATE `stories` SET `showing` = $showing WHERE `id` = '".$row['item_name']."'";
            mysql_query($query2); 
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cron job that I want to execute every 5 minutes: 0,5,10,15,20,25,30,35,40,45,50,55
I want to set up a cron job which will execute a command every
I want to have a cron job that will set the priority of some
I want to set a cronjob entry that runs a script every 30 minutes
I want to set up a cron job. The job has to run every
I want to set up a cron job to run a python script, but
I want to set the cron job in the config file of the Catalog
i want to run a cron job that back ups my mysql database and
I have a cron job that runs every hour. It accesses an xml feed.
Hi guys I want to set up a job pool for my membership based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.