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 7838179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:00:40+00:00 2026-06-02T15:00:40+00:00

I have a small web app built in PHP and Javascript/jQuery. The app involves

  • 0

I have a small web app built in PHP and Javascript/jQuery.

The app involves a random number generator and when it lands on say number 4, the user wins.

However the prize is pulled from a database and after 5 prizes a day are won. the user is unable to win.

Once a user wins, the prize is updated as ‘queued’ until they have filled out a form and claimed the prize. It is then taken out of available prizes.

This all works fine if the user refreshes the app. However if a user begins to play the app and another user wins then the app wont update unless its refreshed as PHP is server side.

I have a javascript function OnStart. So if i could perform the SQL query here it would happen everytime the user throws the die.

How can I run a php statement from a jquery function?

If it helps here is the statement:

$result = mysql_query("SELECT * FROM prizes WHERE dateavailable='$todayDate' AND queue='0' AND won='0' ORDER BY id ASC LIMIT 1");

while($row = mysql_fetch_array($result))

{   
    $prize = $row['prize'];
}

Thanks

EDIT:

So could I possibly use something like this with the php in a seperate file.

<script type="text/javascript">
  function performAjaxSubmission() {
    $.ajax({
      url: 'file.php',
      method: 'POST',
      data: {
        action: 'save',
        arg1: 'val1',
        arg2: 'val2'
      },
      success: function() {
        alert("success!");
      }
    });
    return false; // <--- important, prevents the link's href (hash in this example) from executing.
  }

  jQuery(document).ready(function() {
    $("#linkToClick").click(performAjaxSubmission);
  });
</script>
  • 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-06-02T15:00:51+00:00Added an answer on June 2, 2026 at 3:00 pm

    Save the posted code in a php file, let’s call it prizes_available.php. This file should also output whether prizes are available or not, so create the result object and assign the value to it:

    $result = new stdclass();
    $result->prizes_available = $prize != null;
    echo json_encode($result);
    

    If you call this script in browser, it will output something like this:

    { prizess_available: true }
    

    Using jQuery, you can easily convert this string into an object again:

    $.getJSON('prizes_available.php', function(result)  {
        if (!result.prizes_available) {
            alert('no more prizes');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined small MXML component which calls web service which returns random number
I am a broke college student. I have built a small web app in
I have small web app that generate PDF files as a report. I'm trying
I have an embedded glassfish server and a small web app. I want to
So I have been developing a small ASP.NET web app in C# for my
I have a small web app. Seven pages, 3.6 KB index.html and 855.5 KB
I have a huge web app in Javascript and its starting to become something
I just built a small app with the very cool and minimalistic web.py .
I have a developed a small web-app in Symfony 2 and Doctrine 2. Can
I built a small micro framework for our web service / web app and

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.