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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:12:19+00:00 2026-06-01T15:12:19+00:00

I have to do a blog assignment. In it I have to update a

  • 0

I have to do a blog assignment. In it I have to update a field when someone adds a post. The field is in users table and its name is no_of_posts. When someone posts something the value of no_of_posts related to the user who is logged in should be retrieved then incremented by 1 and updated back to database.

I am trying the following code but its not solving the problem.
$userid holds the current users id.

$userid = $this->Auth->user('id');

$userpost = $this->User->query("SELECT no_of_posts FROM users WHERE id = '$userid'");

$userpost++;

$this->User->query("UPDATE users SET no_of_posts = '$userpost' WHERE id = '$userid'");

I also tried using find but its of no use.

$userpost = $this->User->find('count', array('conditions'=>array('User.id'=>$userid)));

Thanks for any help.

  • 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-06-01T15:12:21+00:00Added an answer on June 1, 2026 at 3:12 pm

    You’ll want to look into counterCache.
    As long as you’ve properly set up the relation between the Post model and the User model (which you should, anyway), Cake keeps track of the post count automatically for you if you just add a few lines of code.

    Check this page in the CakePHP Cookbook: http://book.cakephp.org/1.3/en/view/1033/counterCache-Cache-your-count


    As for what you’re doing wrong in your example: the query call you do returns an array, so it’s only logical that your update query fails.

    Apart from that, using the query() method really isn’t the CakePHP way of doing things. You should really read the Cookbook pages on Models, because now you’re not using CakePHP’s full power. Find the Cookbook pages I mean here: http://book.cakephp.org/1.3/en/view/1000/Models

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

Sidebar

Related Questions

I have to do an assignment of creating a blog with users who can
I have a blog on something.wordpress.com , I simply want one post to ALWAYS
I have a BLOG Table with COMMENTS Table with RESPONSES Table. Example: BLOG ONE
So I have my rails application and I have blog posts in my application.
I have a blog. On the individual post page I want to display a
I have a blog app and i want to show each post in a
I want to store blog and its tags as separate documents. Blog post should
See the bullets on this blog post: http://www.nielsbrinch.com/managing-expectation-management/ I have had to change to
Let's say I have blog entries like these in my CouchDB database: {name:Mary, postdate:20110412,
I have a blog article that contains three elements: 1) the post thumbnail, 2)

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.