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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:24:08+00:00 2026-06-11T00:24:08+00:00

I had previously asked a question MYSQL Searching multiple tables with different columns using

  • 0

I had previously asked a question MYSQL Searching multiple tables with different columns using LIKE

Which I was unable to get help on: so I’m compromising.
Right now if a person makes a search and its found in multiple tables it does not search them in the order I want. I’d like for results to come first from the connectors table, then adapters table, then components table. If a result is found in connectors, dont search adapters or components, just continue.

I’ve also tried putting them in this order without using else if: components, adapters, connectors. That didn’t work though.

if(isset($_GET['num'])) {
$num = $_GET['num'];
$numresult = mysql_query("SELECT * FROM productnumber WHERE part_num LIKE '%$num%'");

  if ($numresult) {

    while ($row = mysql_fetch_array($numresult)) {

        if ($row["title"] == "connectors") {
            $numtitle = "connectors";
            $result = mysql_query("SELECT * FROM connectors WHERE part_num LIKE '%$num%'");
        } else if ($row["title"] == "adapters") {
            $numtitle = "adapters";
            $result = mysql_query("SELECT * FROM adapters WHERE part_num LIKE '%$num%'");
        } else if ($row["title"] == "components") {
            $numtitle = "components";
            $result = mysql_query("SELECT * FROM components WHERE part_num LIKE '%$num%'");
        }   

    }
  }
}
  • 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-11T00:24:10+00:00Added an answer on June 11, 2026 at 12:24 am

    This is the code using the mysql_* methods: This code will search in connectors if nothing is found then it will search in adapters and so on. but as you requested If it has found something in connectors it won’t check in adapters or components!

    <?php
    if(isset($_GET['num'])) {
    $num = $_GET['num'];
        // We will first search for connectors
        $result = mysql_query("SELECT * FROM connectors WHERE part_num LIKE %'$num'%");
        if(mysql_num_rows($result) == 0) {
        // Now if we don't find anything in connectors, we will search in adapters
        $result = mysql_query("SELECT * FROM adapters WHERE part_num LIKE %'$num%'%");
        if(mysql_num_rows($result) == 0 ){
        // And if we don't find anything in adapters, finally we will search in components
        $result = mysql_query("SELECT * FROM components WHERE part_num LIKE %'$num%'%"); 
        if(mysql_num_rows($result) == 0) {
            echo "We Found Nothing! :( "
        }
        }}
    }
    ?>
    

    And this is a sample code ( just your code ) converted to PDO. but not a right answer for your question.

     <?php
        try {
            $conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $qry = $conn->prepare('SELECT * FROM productnumber WHERE part_num LIKE %:part_num%');
            $qry->execute(array(':part_num'=>$_GET['num']));
            $row = $qry->fetch(PDO::FETCH_OBJ)
                switch ($row->title) {
                    case 'connectors':
                    $numtitle="connectors";
                    $qry2=$conn->prepare('SELECT * FROM connectors WHERE part_num LIKE %:num%');
                    $qry2->execute(array(':num'=>$_GET['num'])));
                    break;
                    case 'adapters':
                    $numtitle="adapters";
                    $qry2=$conn->prepare('SELECT * FROM adapters WHERE part_num LIKE %:num%');
                    $qry2->execute(array(':num'=>$_GET['num'])));
                    break;
                    case 'components':
                    $numtitle="components";
                    $qry2=$conn->prepare('SELECT * FROM components WHERE part_num LIKE %:num%');
                    $qry2->execute(array(':num'=>$_GET['num'])));
                    break;
                }
        } catch(PDOException $e) {
            echo 'ERROR: ' . $e->getMessage();
        }
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had previously also asked a question on this and was unable to get
I had previously asked this question, trying to get started with this code: The
I know I asked a related question earlier. I just had another thought. using
I had previously asked about Converting using SqlConnection to Func delegate How can I
I previously asked this question here: Stop user from using enter to pass a
I asked this question previously and thought I had it figured out but it
I had asked this question previously on SO. This is related to it. We
I am working on this problem and had previously asked related question. Implementation of
I previously had a table that is created using hibernate entities. I am using
I have a follow-up question regarding an issue I previously had on SO here

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.