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

Thursday, March 3, 2022

[FIXED] Search All Attribute in one textbox

 March 03, 2022     php, yii, yii2     No comments   

Issue

enter image description here I have a table: Email, and the attributes: id, subject, content, to, cc, ...

Then in the index, there is only one search box. I want this search-box can search all value in each attribute.

Like this picture above, we can search by "To" attribute, or "Subject" attribute or other attributes in 1 search textbox.

enter image description here enter image description here

Should i code in the controller or in the index view?

I hope all of you can share the code, so can complete this task.

Thank you and have a great day


Solution

After search value filtered in following fields if $search variable is empty then orFilterWhere function ignore that condition in query

$model = User::find() 
$model
->orFilterWhere(['like', 'name', $search])
->orFilterWhere(['like', 'email', $search])
->orFilterWhere(['like', 'address', $search])
->asArray()
->all();


Answered By - Shringiraj Dewangan
  • 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