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

The Archive Base Latest Questions

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

I am trying to build a page that uses jQuery to call a database

  • 0

I am trying to build a page that uses jQuery to call a database every second and return the highest numbered row.

The jQuery code is below (this is in $(‘document’).ready)

    var id = 0;
    $.post('check.php', 'id=0', function(data){
         id = parseInt(data); 
         $('h1').text(data);
    });

    var timer = setInterval(function() {
        $.post('check.php', 'id=' + id, function(data){
            if (data != '')
                $('h1').text(data)
            else
                $('h1').text("NOTHING!");
        id = parseInt(data);
        });
    }, 1000);

And the PHP file, check.php, has the following code (after connecting to the database):

$id = $_POST['id'] - 1;
$query = "SELECT * FROM testtable WHERE 'id' > $id ORDER BY id DESC";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
echo "$row[0]";

When ‘id’ is the first column.
The highest row number right now is 13. I would expect it to send 13 to the PHP file. $id would then be 12, so it would select all rows with id values higher than 12, returning the row with id value 13. Then it would echo “13”, which is sent back to jQuery, which is parsed to an integer, making id equal to 13. Then 13 is sent to the PHP file again a minute later, and the process cycles.

What’s actually happening is that it’s alternating between displaying “13” and “NOTHING!”, and I can’t figure out why.

  • 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-27T23:16:59+00:00Added an answer on May 27, 2026 at 11:16 pm

    Because select * from tesstable where id > 13 will always be an empty result if 13 is the highest id. What you want is this:

    select max(id) as id from testtable

    You don’t have to send back $id, and if it’s got an index on it, this query will return very quickly.

    Also, your original query has the column id in quotes, not backticks. You’re comparing the string “id” with your variable $id. To top that off, you’re susceptible to SQL injection here, so use mysql_escape_string, PDO, or remove the variable reference altogether using the max query provided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've built a page using jQuery that uses an async Ajax call. I'm trying
I'm trying to build a page on my personal website that both used jQuery
I'm trying to build a Javascript listener for a small page that uses AJAX
I am trying to build a page that will allow me to take an
I'm trying to build a Web page that has a rich text editor. Is
I'm trying to build a control logic that depends on the current gsp page
Im trying to build call to action button on my site using jQuery. I
I am trying to build a native client module that uses the improv lib
I've built a login page that uses a .ajax call to a generic c#
Question I'm trying to build a quick and easy ASP.NET page that redirects a

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.