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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:07:06+00:00 2026-05-26T20:07:06+00:00

I tried myself for another queries but this one is more complex for me

  • 0

I tried myself for another queries but this one is more complex for me as i am new to zend. Please help me i tried different ways but not worked.

Tour Id fetching from another query

$tourId = $row2 ['test_public_id'];

$query = select count(ms.test_public_id) as total_views, ms1.recent_views from test_stats 
ms join (select count(test_stats.test_public_id) as recent_views 
from test_stats  where test_stats.test_public_id = '$tourId' 
and test_stats.updated_on > DATE_SUB(CURDATE(), INTERVAL 7 DAY)) ms1 
where ms.test_public_id ='$tourId'" ;
  • 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-26T20:07:07+00:00Added an answer on May 26, 2026 at 8:07 pm

    Something like that should work:

    $subselect = $dbAdapther->select()->from(
      array('test_stats' => 'test_stats'),
      array(
        '(COUNT(test_public_id)) AS recent_views'
      )
    )->where(
      $dbAdapther->quoteInto('test_stats.test_public_id = ?', $tourId)
    )->where(
      'test_stats.updated_on > DATE_SUB(CURDATE(), INTERVAL 7 DAY)'
    );
    
    $select = $dbAdapther->select()->from(
      array('ms' => 'test_stats'),
      array(
        '(COUNT(ms.test_public_id)) AS total_views' // COUNT should be in brackets to preevent Zend from interpreting it as a field name
      )
    )->join(
      array('ms1' => $subselect),
      '',
      array(
        'ms1.recent_views'
      )
    )->where(
      $dbAdapther->quoteInto('ms.test_public_id = ?', $tourId)'
    );
    

    Although I’d have your query broken into two separate ones or, more precisely, write a universal “get number of views” query with a date as its parameter, and then I’d be calling it twice, with or without the date.

    But if you still need to get those two figures in one go in a single row (i.e. you can’t use UNION instead of your unnecessary JOIN), I’d recommend you to use the following code instead:

    $select = $dbAdapther->select()->from(
      array('ms' => 'test_stats'),
      array(
        '(COUNT(ms.test_public_id)) AS total_views',
        '(
          COUNT(
            CASE
              WHEN ms.updated_on > DATE_SUB(CURDATE(), INTERVAL 7 DAY)) THEN ms.test_public_id
              ELSE NULL
            END
          )
        ) AS recent_views'
      )
    )->where(
      $dbAdapther->quoteInto('ms.test_public_id = ?', $tourId)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is a very simple question, but I’m new to programming so
Im sure this is another time I'm over complicating things, or just making myself
EDIT: My sincere apologies! This wasn't an issue with anything but myself - I
So I'm afraid this is another one of those slideshow questions that clutters up
I tried to wean myself of lopping everything in a Session variable in ASP.NET
[First, I'm an absolute beginner. I tried to express myself as good as I
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Tried a bunch of things but I can't get it to work consistently amid

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.