PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to get only one value from database query?

 April 22, 2022     cakephp-2.3     No comments   

Issue

I got a row from database table now I wish to echo only one value from this row in CakePHP. So how to do it?

$help = $this->help->findByControllerAndAction($controller ,$action)

it has four values: id, controller, action and help_text. I want to echo only controller. Any help?


Solution

I suggest reading some of the documentation, more specifically this section.

To answer your question...

I assume your Help model has a unique key controller+action.

In your controller's method you will need:

$help = $this->Help->findByControllerAndAction($controller ,$action);
if ($help) {
    $this->set('help', $help);
}

In your view:

echo $help['Help']['controller'];

will show the content of the Help.controller field.

Use:

debug($help);

If $help is not defined in your view, chances are your find is not returning the results you expect.



Answered By - savedario
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing