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

  • SEARCH
  • Home
  • 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 6971703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:52:27+00:00 2026-05-27T16:52:27+00:00

I need help, This is what am actually trying to do. I have two

  • 0

I need help, This is what am actually trying to do. I have two files. “index.php” and “realtime.php” the index.php displays news from a particular country base on the url parameter “country_code”, and the realtime.php updates the news list every 2 seconds. what I want is for realtime.php to get the current url parameter of index.php so that it can only update news from that particular country base on the url parameter. I really need this help. Thank you again.
script for index.php

<script type="text/javascript">
$(document).ready(function () {
    $.arte({'ajax_url': '../realtime.php?lastid='+$('.postitem:first').attr('id'), 'on_success': update_field, 'time': 1000}).start();
    function update_field(data)
    {
        $("#realtimeupdate").html(data);
    }
});

</script>

and script for realtime.php

<?php

include"customDB.php";
$lastid = $_REQUEST['lastid'];
$query = 'SELECT count(*) as newpost FROM wp_posts WHERE country_code = "XXXXX" AND   post_id > "'.$lastid.'"';
$result = mysql_query($query);
$rec = mysql_fetch_object($result);
if($rec->newpost){ ?>
<a href="" id="newpostlink">(<?php echo $rec->newpost; ?>) new posts</a>
<script type="text/javascript">document.title = '(<?php echo $rec->newpost; ?>) new posts'</script>
<?php } ?>

I want the value of country_code =”XXXXXX” in raltime.php to be the url parameter value of index.php
Thanks

  • 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-27T16:52:28+00:00Added an answer on May 27, 2026 at 4:52 pm

    Accessing query string in Javascript

    First, you’ll need to get the value of “country_code” that has been passed as a query string parameter. You can use Javascript like this to do so:

    var urlParams = {};
    (function () {
        var e,
            a = /\+/g,  // Regex for replacing addition symbol with a space
            r = /([^&=]+)=?([^&]*)/g,
            d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
            q = window.location.search.substring(1);
    
        while (e = r.exec(q))
           urlParams[d(e[1])] = d(e[2]);
    })();
    

    (taken from this SO question)

    Now, urlParams will look something like:

    urlParams = {
        country_code: 'US'
    }
    

    So, you can change your AJAX call to add this parameter:

    $.arte({'ajax_url': '../realtime.php?country_code='+urlParams.country_code+'lastid='+$('.postitem:first').attr('id'), 'on_success': update_field, 'time': 1000}).start();
    

    And now it will be available via PHP under $_GET['country_code'].

    Using the variable in PHP

    Now you can access the variable and use it in your query.

    $country_code = mysql_real_escape_string($_GET['country_code']);
    $query = 'SELECT count(*) as newpost FROM wp_posts WHERE country_code = "' . $country_code . '" AND   post_id > "'.$lastid.'"';
    

    Note that I’ve written this code to conform to your existing coding style. It’s not very clean, so you might consider cleaning it up by using helpers like $.param() and MySQLi prepared statements.

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

Sidebar

Related Questions

I need help finishing this statement. It is frustrating that two of the PHP
I need the community's help on this. We have TFS 2010 and SharePoint services
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I really need help on this one. I am having a simple login form
Not exactly about programming, but I need help with this. I'm running a development
Sorry to bother again, but I really need help transforming this Python2 code into
Need some help with this problem in implementing with XSLT, I had already implemented
I need help in turning this linq expression into a linq statment. SampleData.Publishers and
I need some help understanding this bit of code pre { white-space: pre; white-space:

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.