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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:02:50+00:00 2026-06-14T15:02:50+00:00

I’m sort of new to CakePHP and can’t figure out how sql queries work

  • 0

I’m sort of new to CakePHP and can’t figure out how sql queries work here. I have a delete button which erases news about players. What it’s not doing (and it should) is also take care of number of news, which is stored in “news” column in “fc_players” table. In an old-fashioned way I’d go like:

("SELECT player FROM entries WHERE id = '" . $id . "'");

(returns $name of the player; can’t just use $id because of how database is built; “entries” is a table where news are stored)

("SELECT news FROM fc_players WHERE name = '" . $name . "'");

(returns how many news about certain player is in the database)

If only one, delete $name from database:

("DELETE FROM fc_players WHERE name = '" . $name . "'");

I’ve tried to do:
$this->FCPlayer->deleteAll(array('FCPlayer.name' => $name)); but for some reason it doesn’t work.

If more, simply reduce it:

$news = $news - 1;

("UPDATE fc_players SET news = '" . $news . "' WHERE name = '" . $name . "'");

I can handle it in plain PHP but Cake is a bit harder and I can’t find any useful examples. Can you help me to translate it from sql queries to CakePHP or guide me to articles which are actually explaining it?

Thanks!

EDIT:

Ok, Nik and Steve, thanks for you answers. Unfortunately it doesn’t solve my problem. I think there’s something wrong with handling sql queries.

$this->Session->setFlash($id, 'success'); shows me correct entry id, so $id is fine.

But when I’m trying to get player name with:

$player = $this->Entry->field("player", array("id" => $id));

or with

$this->Entry->id = $id;
$player = $this->Entry->field('player');

or execute query

player = $this->Entry->query("SELECT player FROM entries WHERE id = '" . $id . "'");

the result is blank. I did manage to get player name by doing:

$player = $this->Entry->field('player');

but it simply returned name of the player from most recent entry, not the one I’m deleting.

I just can’t figure out where I’m making mistake. Is it possible that it returns some kind od array or object that setFlash cannot process? If so, why last example works (sort of)?

  • 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-14T15:02:51+00:00Added an answer on June 14, 2026 at 3:02 pm

    When you delete a piece of news, CakePHP wont take care of the number of views in any other table. Is not so intelligent yet 🙂

    You have to change it manually.

    You can use something like:

    $number_of_news = $this->Player->field("number_of_news", array("id" => $id));
    
    $this->Player->set("number_of_news" => $number_of_news - 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.