Search with a joined table using YII
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have the following table structure. tb_posts has the field author_id which relates to tb_author.id in YII i have the following in my posts activeRecord , Set table alias for your models at init. class PostsRecord extends CActiveRecord
{
// ...
public function init() { $this->setTableAlias( 'postsrecord' ); }
// ...
}
class AuthorRecord extends CActiveRecord
{
// ...
public function init() { $this->setTableAlias( 'authorrecord' ); }
// ...
}
$condition=new CDbCriteria;
$condition->with = array('authorRelation');
$condition->together = true;
$condition->condition = 'authorrecord.name=:authorname';
$condition->params = array( ':authorname' => 'foo' );
$posts=PostsRecord::model()->findAll($condition);
|
.net MVC search to query joined table
Date : March 29 2020, 07:55 AM
I wish this helpful for you Came across the answer to this while working on something else. Here's my final code on this. Hope its useful to someone. var customer = from c in db.Customer
select c;
if (!String.IsNullOrEmpty(searchString))
{
customer = customer.Where(c => SqlFunctions.StringConvert((double)c.CustomerID).Trim().Equals(searchString)
|| c.CustomerName.ToUpper().Contains(searchString.ToUpper())
|| c.Postcode.ToUpper().Replace(" ", "").Equals(searchString.ToUpper().Replace(" ", ""))
|| c.Telephone.ToUpper().Replace(" ", "").Equals(searchString.ToUpper().Replace(" ", ""))
|| c.CustomerContact.Where(x => x.FirstName.ToUpper().Contains(searchString.ToUpper())).Any()
|| c.CustomerContact.Where(x => x.Surname.ToUpper().Contains(searchString.ToUpper())).Any()
|| c.CustomerContact.Where(x => (x.FirstName.ToUpper() + " " + x.Surname.ToUpper()).Contains(searchString.ToUpper())).Any());
}
|
search for fullname on joined table
Date : March 29 2020, 07:55 AM
This might help you You can't use an alias name like full_name in the WHERE clause, see manual SELECT wrs.id, wrs.fname, wrs.sname, wrs.email1, wrs.applied, wrs.firstlogin, wrs.tel1,
SUBSTR( wrs.lastlogin, -10 ) AS last_login,
CONCAT_WS( ' ', wrs.fname, wrs.sname ) AS full_name, wqs.level,
wqs.subject, wqs.university, wqs.dissertation
FROM temp_users AS wrs
LEFT JOIN writer_qualifications AS wqs ON wqs.writer_id = wrs.id
WHERE wrs.fname LIKE '%micky%'
OR wrs.sname LIKE '%micky%'
OR CONCAT_WS( ' ', wrs.fname, wrs.sname ) LIKE '%micky%'
AND wrs.status = '1'
GROUP BY wrs.id
|
Search in joined table with multiple records
Tag : mysql , By : gbodunski
Date : March 29 2020, 07:55 AM
will help you I have a table 'contacts' which is structured like this: , A possible solution is SELECT
DISTINCT C.*
FROM
contacts C LEFT JOIN contacts_related R
ON C.id=R.contact_id
WHERE
C.name LIKE '%John%' OR
R.name LIKE '%John%'
|
How do I search in joined table?
Tag : php , By : Harry Truman
Date : March 29 2020, 07:55 AM
seems to work fine Here is my code working perfectly. you can try this stuff i hope this will work for you. public function index()
{
/*$email=$this->post->input('search');*/ //OR
$email='myEmail@test.com'; // Set email accroding you
$this->db->select('*');
$this->db->from('table1');
$this->db->like('table1.email',$email);
$this->db->join('table2', 'table1.email = table2.email');
$query = $this->db->get();
$assignedData=$query->result_array();
var_dump($assignedData); // store data in array
}
|