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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:53:57+00:00 2026-05-24T04:53:57+00:00

I have three tables: ‘users’, ‘products’, and ‘product_types’. The ‘users’ table stores all usual

  • 0

I have three tables: ‘users’, ‘products’, and ‘product_types’. The ‘users’ table stores all usual data about my site users (including an id column); the ‘products’ table lists the product_id of the product, the user_id of the user who added it, and the product_type; the ‘product_types’ table has an id column (which corresponds with the product_type int value in the ‘products’ table), and a varchar name column.

I want to perform a %like% search in the ‘users’ table so that when a user searches for product types, it shows all users who have products that match the searched product type. Here’s what I’m currently using in my CodeIgniter model:

$string = urldecode($string);
$this->db->select('users.*');
$this->db->from('users');
$this->db->like('users.company_name',$string,'both');
$this->db->or_like('users.address_1',$string,'both');
$this->db->or_like('users.city',$string,'both');
$this->db->or_like('users.contact',$string,'both');
$this->db->or_like('product_types.name',$string,'both');
$this->db->join('products','users.id = products.client_id');
$this->db->join('product_types','products.product_type = product_types.id');
$this->db->distinct();
$users = $this->db->get();
foreach($users->result() as $user){
   // search result
}

I then feed this into a foreach statement… But it’s only showing the first row most of the time – other times it comes back with no results. Can anybody tell me where I’m going wrong?

  • 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-05-24T04:53:58+00:00Added an answer on May 24, 2026 at 4:53 am

    I dont understand why you are making multiple queries, it can be accomplished only in one query

        SELECT a.*,b.*,C.* FROM users a LEFT JOIN products b ON b.user_id = a.id LEFT JOIN product_types c ON b.product_type = c.id WHERE a.company_name LIKE '%$string%' OR a.address_1 LIKE '%$string%' OR a.city LIKE '%$string%' a.contact LIKE '%$string%' b.name LIKE '%$string%' 
    

    this will give you all the products of the user with there product type, try to run it on your db to see it in action. then use foreach statement to fetch the results

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables, table one (tableA) containing users data like name and email,
I have three tables...users, user_info, and quota_levels. They look like this: CREATE TABLE users
I have three tables, Products(ProductID, ProductName) Orders(OrderID, OrderDate) OrderDetails(ProductID, OrderID) Junction table between Products
I have three tables, 1-Users, 2-Softwares, 3-UserSoftwares. if suppose, Users table having 6 user
I have three tables: Users, Groups and GroupsUsers User table: id: 1 username: admin
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three tables tag , page , pagetag With the data below page
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables, one of users, one of cases, and one with links
I have three tables. First table is Activities and second is Members and last

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.