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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:38:41+00:00 2026-05-29T20:38:41+00:00

I have the following php script that is called by jquery ajax function report_range($time,

  • 0

I have the following php script that is called by jquery ajax

    function report_range($time, $ht, $start_date, $end_date) {
        $query = mysql_query("SELECT type, count(*) FROM tracking WHERE htcode = '$ht' AND type IN ('viewed', 'shared', 'printed', 'emailed', 'used') AND date >= '$start_date' AND date <= '$end_date' GROUP BY type");
        while ($result = mysql_fetch_assoc($query)){
            switch ($result['type']){
                case 'viewed':
                    $viewed = $result['count(*)'];
                    break;
                case 'shared':
                    $shared = $result['count(*)'];
                    break;
                case 'used':
                    $used = $result['count(*)'];
                    break;
                case 'emailed':
                    $emailed = $result['count(*)'];
                    break;
                case 'printed':
                    $printed = $result['count(*)'];
                    break;
            }

        }
        //build the table rows
        return '<tr><td>'.$time.'</td><td>'.$viewed.'</td><td>'.$shared.'</td><td>'.$used.'</td><td>'.$printed.'</td><td>'.$emailed.'</td></tr>'; 
//this is where the problem is, i dont think i am returning the value right.

    }

//create the variables to send to json

    $stat_1 = report_range('Today', '1672627', date('Y-m-d'), date('Y-m-d'));
    $stat_2 = report_range('Yesterday', $_POST['htcode'], date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime('yesterday')));
    $stat_3 = report_range('Past 30 Days', $_POST['htcode'], date('Y-m-d', strtotime('30 days ago')), date('Y-m-d'));
    $stat_4 = report_range('All Time', $_POST['htcode'], date('Y-m-d', strtotime('3600 days ago')), date('Y-m-d'));

//create the json array

echo json_encode(array(
        'stat_1'=>$live_1,
        'stat_2'=>$live_2,
        'stat_3'=>$live_3,
        'stat_4'=>$live_4
    ));

i can not seem to get a json array with the four variables containing the table rows i am building in the function.

The jquery is working, as it shows the null values.

  • 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-29T20:38:42+00:00Added an answer on May 29, 2026 at 8:38 pm

    Shouldn’t that $live_1 etc var be $stat_1?

    echo json_encode(array(
            'stat_1'=>$stat_1,
            'stat_2'=>$stat_2,
            'stat_3'=>$stat_3,
            'stat_4'=>$stat_4
        ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function, 'redirect_to()' written on php script that is called after a
I have the following problem: A PHP Script is called via Ajax. The script
I have the following situation. I have a PHP script that imports a CSV
I have a PHP script that does the following: Uses file_get_contents() to get content
I'm using Firefox 3.6.6. I have a PHP script called index.php with the following
I have the following jQuery function that I'm using to display a timer on
I have the following PHP script: <?php $fortune = `fortune`; echo $fortune; ?> but
i have the following simple script <input class=input type=text name=password style=color: #797272; value= <?php
I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php
I am new to Ajax and have been following a tutorial from JQuery.com. I

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.