Welcome Guest, Not a member yet? Register   Sign In
one search term - two sets of results. how to?
#1

[eluser]zoreli[/eluser]
Hi

I have a search form. I would like when someone type the term, first to search trough users table and to return his name, username, e-mail etc...and next I should perform another query with the SAME search term from another table example: posts and return posts with the user name and the post.

So I have to return and display 2 sets of results. I must admit that I am totally lost, and have no idea how to proceed.

Anyone can help me with an idea how to do this with codeigniter?

Thanks in advance, Zoreli
#2

[eluser]alsemany[/eluser]
as the example above you need this
Code:
$get_post = $this->db->get_where('posts', array('id'=>$postid));

$post = $get_post->row(); //one row


$get_related_posts = $this->db->get_where('posts' , array('userid'=> $post->userid) );

$related_posts = $get_related_posts->result(); //(multiple rows) you will use foreach function


if you want to get how many posts by user
Code:
$num_posts = $get_related_posts->num_rows();
#3

[eluser]CI_expert_indian[/eluser]
You can use Joins in mysql .




Theme © iAndrew 2016 - Forum software by © MyBB