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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:38:38+00:00 2026-05-26T07:38:38+00:00

i use my own mvc framework. and post action is : function post($pid =

  • 0

i use my own mvc framework.

and post action is :

function post($pid = 0 , $title = '')
{

    $pid = $this->input->clean($pid);

    $stm =$this->Post->query("UPDATE posts SET `show_count`=show_count+1 WHERE id = $pid"); 
    $stm->execute();
    $row = $this->Post->find()->where(array('id'=>$pid))->fetchOne();
    $this->layout->set('comments' ,  $this->comments($pid));
    $this->layout->set('row' , $row);
    $this->side();
    $this->layout->view('post'); 
    echo $this->layout->render($row['title']);
}

i want to when a record fetch from database plus one show_count column .

i use this query :

UPDATE posts SET show_count = show_count + 1 WHERE id = $pid

this right in localhost but in my shared host when run query instead of one pluses ,2 plus show_count column.

how can i solve this problem?

  • 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-26T07:38:39+00:00Added an answer on May 26, 2026 at 7:38 am

    It’s working in your localhost but not your internet host. The host is probably doing something behind the scenes that makes it not work. Also, since you don’t have access to all the configuration stuff on the host server, you probably won’t be able to just fix it.

    Simplest fix is to do it in the software layer (assuming $pid is unique).

    First get the show_count.

    Then:

    $oldShowCount = the current show_count
    $newShowCount = $oldShowCount + 1
    
    UPDATE posts SET show_count = $newShowCount WHERE id = $pid AND show_count = $oldShowCount
    

    At this point, if no race conditions occurred the row will update (rows update = 1). If a race condition occurred, the update will fail (rows updated = 0).

    Then check the # rows updated to verify it worked and repeat until it does.

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

Sidebar

Related Questions

I am trying to use my own function to get the file size from
This is really just for my own use: I would like to be able
Instead of app-id@appspot.com or any@app-id.appspot.com I would like to use any@own-domain.tld. can this be
I want to use a javascript framework with MVC for a complex web application
I have been developing my own PHP MVC framework. Now I have seen different
So I'm working on my own little MVC framework as a learning exercise. It's
I use Catalyst (MVC framework for Perl), but the question probably apply to all
I've just started to build my very own MVC framework. Feel's kind of nice
Recently I've started to use Zend framework next to my own framework. The solution
I've built my own educational MVC framework to learn more about PHP OOP, which

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.