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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:02:42+00:00 2026-05-20T12:02:42+00:00

I’ve spent the last two days trying to find a solution to this problem

  • 0

I’ve spent the last two days trying to find a solution to this problem so anyone that can either provide a solution or a link to somewhere I could find out what I need to know would be doing me a huge favour.

I’ve got the following model relationships in CakePHP

Keyword hasMany Click

I want to construct a query (either through $this->Keyword->find or by using a custom query) that will return a list of similar keywords ordered by the number of clicks they’ve received in the last week. Unfortunately I can’t just use the counterCache ‘click_count’ field to do this because I need to only count clicks that occurred in the last week. To further complicate things I’ve got to add a LIKE() condition to the keyword field too.

Here is what I’ve got so far:

$result = $this->Keyword->find('all',array(
        'conditions' => array(
            'word_count >' => $keyword['Keyword']['word_count'],
            'UPPER(keyword) LIKE' => "%".strtoupper($keyword['Keyword']['keyword'])."%"
        ),
        'recursive' => 0,
        'limit' => 10
    ));

I just need to add the bit that sorts these results by the number of associated Click records where Click.created is within the last week. I’ve worked out that that part should look something like:

array(
        'conditions' => array(
            'Click.created >' => date("Y-m-d",strtotime("1 week ago"))
        ),
        'fields' => array(
            'COUNT(Click.keyword_id) as count'
        ),
        'group' => 'Click.keyword_id',
        'order' => 'count DESC'
    );

I’m just not sure where this bit should go.

Please could someone put me out of my misery? 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-20T12:02:43+00:00Added an answer on May 20, 2026 at 12:02 pm

    Well, I managed to blag an SQL query that does what I needed from this page: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_20646898.html

    Here is what it looks like:

    SELECT *
            FROM keywords
            AS Keyword
            LEFT JOIN (SELECT keyword_id,count(*) AS click_count FROM clicks GROUP BY keyword_id)
            AS Click
            ON Keyword.id = Click.keyword_id
            WHERE Keyword.word_count > ".$keyword['Keyword']['word_count']."
            AND UPPER(Keyword.keyword) LIKE '%".strtoupper($keyword['Keyword']['keyword'])."%'
            ORDER BY Click.click_count DESC
    

    Hopefully someone else will find this useful.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.