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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:23:30+00:00 2026-06-07T22:23:30+00:00

I’m currently coding my own CMS and I’m at the point of the search.php

  • 0

I’m currently coding my own CMS and I’m at the point of the search.php. I need to search in 4 tables that haves different columns name within only one query because my server is not the fastest.

There’s my DB arrangement:

cmw_admin (users table)

+-----------------+------------+------+-----+---------+----------------+
| Field           | Type       | Null | Key | Default | Extra          |
+-----------------+------------+------+-----+---------+----------------+
| id              | int(11)    | NO   | PRI | NULL    | auto_increment |
| role            | int(11)    | NO   |     | 1       |                |
| username        | text       | NO   |     | NULL    |                |
| password        | text       | NO   |     | NULL    |                |
| email           | text       | NO   |     | NULL    |                |
| phone           | text       | NO   |     | NULL    |                |
| location        | text       | NO   |     | NULL    |                |
| full_name       | text       | NO   |     | NULL    |                |
| bio             | text       | NO   |     | NULL    |                |
| website         | text       | NO   |     | NULL    |                |
| last_login      | datetime   | NO   |     | NULL    |                |
| registered_date | datetime   | NO   |     | NULL    |                |
| registered_ip   | text       | NO   |     | NULL    |                |
| credits         | tinyint(1) | NO   |     | NULL    |                |
| online          | int(11)    | NO   |     | 0       |                |
+-----------------+------------+------+-----+---------+----------------+

cmw_blog (articles table)

+------------+----------+------+-----+---------+----------------+
| Field      | Type     | Null | Key | Default | Extra          |
+------------+----------+------+-----+---------+----------------+
| id         | int(11)  | NO   | PRI | NULL    | auto_increment |
| title      | text     | NO   |     | NULL    |                |
| content    | text     | NO   |     | NULL    |                |
| date       | datetime | NO   |     | NULL    |                |
| author     | int(11)  | NO   |     | NULL    |                |
| categories | text     | NO   |     | NULL    |                |
| media      | text     | NO   |     | NULL    |                |
| thumb      | text     | NO   |     | NULL    |                |
+------------+----------+------+-----+---------+----------------+

cmw_projects (portfolio)

+-------------+------------+------+-----+---------+----------------+
| Field       | Type       | Null | Key | Default | Extra          |
+-------------+------------+------+-----+---------+----------------+
| id          | int(11)    | NO   | PRI | NULL    | auto_increment |
| owner_id    | int(11)    | NO   |     | NULL    |                |
| title       | text       | NO   |     | NULL    |                |
| content     | text       | NO   |     | NULL    |                |
| date        | date       | NO   |     | NULL    |                |
| link        | text       | NO   |     | NULL    |                |
| img         | text       | NO   |     | NULL    |                |
| type        | int(11)    | NO   |     | NULL    |                |
| start_date  | date       | NO   |     | NULL    |                |
| end_date    | date       | NO   |     | NULL    |                |
| done        | tinyint(1) | NO   |     | 0       |                |
| screenshots | text       | NO   |     | NULL    |                |
+-------------+------------+------+-----+---------+----------------+

cmw_services (services table)

+-------------+---------------+------+-----+---------+----------------+
| Field       | Type          | Null | Key | Default | Extra          |
+-------------+---------------+------+-----+---------+----------------+
| id          | int(11)       | NO   | PRI | NULL    | auto_increment |
| cat_id      | int(11)       | NO   |     | NULL    |                |
| name        | text          | NO   |     | NULL    |                |
| description | text          | NO   |     | NULL    |                |
| img         | text          | NO   |     | NULL    |                |
| price       | decimal(11,2) | NO   |     | NULL    |                |
+-------------+---------------+------+-----+---------+----------------+

In my search, I need to search for string in every name/title columns and in all description/content columns too. In clear, I want to search all those table for one string, in only one query. Is that possible? I know that using JOIN, LEFT JOIN, RIGHT JOIN and INNER JOIN may be easy but I don’t know how to use them. Google is not very explicit on that things!

  • 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-06-07T22:23:32+00:00Added an answer on June 7, 2026 at 10:23 pm

    The total cost of four straight queries is in all likelihood much less than the cost of a JOIN plus a search of those same records/fields.

    If anything, check the possibilities of a FULLTEXT index.

    In any case, you can do this with something like

     SELECT "cmw_admin" as source, id FROM cmw_admin, NULL as date [...] WHERE bio LIKE '%search%'
     UNION
     SELECT "cmw_blog"  as source, id FROM cmw_admin, date as date [...] WHERE
         (title LIKE '%search%' OR content LIKE '%search%')
     UNION
     ...
    

    which will give you a list of the found records, together with a hint of where the record came from (“cmw_admin”, “cmw_blog”, …); that will allow you to choose how to present the records from the various sources.

    The query will always return the same set of fields, some with valid values, some not, depending on what the “source” is. Then in your PHP script you can do something like,

     $source = $record['source'];
     if (!isset($template[$source]))
         $template[$source] = file_get_contents("templates/search/$source.html");
    
     $html_view = preg_replace('#{{\s*([^}\s]*)\s*}}#e', 'isset(\$record["\1"])?\$vars["\1"]:""', $template[$source]);
    

    This will take a HTML template containing a HTML fragment like

     <h2>{{ date }}</h2>
    

    and “populate” the field with the [date] entry of the current $record. I find this is a good way to keep HTML and code separated (YMMV). If you already have a templating system, you can (and should!) adapt that one instead.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.