mysql apply wildcards in multiple table not working
I'm trying to make search box which can search from multiple tables using mysql wildcards and show the result as output.
The error code is:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:xampphtdocstestcrud21search.php on line 16
mysql wildcard
add a comment |
I'm trying to make search box which can search from multiple tables using mysql wildcards and show the result as output.
The error code is:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:xampphtdocstestcrud21search.php on line 16
mysql wildcard
Please, post more information about the error. You're telling is not working, but you didn't provide the error message.
– Sakura Kinomoto
Nov 25 '18 at 19:43
1
Post your code as plain text, not an image. See formatting for code formatting help.
– Barmar
Nov 25 '18 at 19:50
1
UseUNION
, not a cross product.
– Barmar
Nov 25 '18 at 19:50
Every table name has different column name @Barmar
– Hozayfa
Nov 25 '18 at 19:53
add a comment |
I'm trying to make search box which can search from multiple tables using mysql wildcards and show the result as output.
The error code is:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:xampphtdocstestcrud21search.php on line 16
mysql wildcard
I'm trying to make search box which can search from multiple tables using mysql wildcards and show the result as output.
The error code is:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:xampphtdocstestcrud21search.php on line 16
mysql wildcard
mysql wildcard
edited Nov 25 '18 at 19:52
Hozayfa
asked Nov 25 '18 at 19:40
HozayfaHozayfa
62
62
Please, post more information about the error. You're telling is not working, but you didn't provide the error message.
– Sakura Kinomoto
Nov 25 '18 at 19:43
1
Post your code as plain text, not an image. See formatting for code formatting help.
– Barmar
Nov 25 '18 at 19:50
1
UseUNION
, not a cross product.
– Barmar
Nov 25 '18 at 19:50
Every table name has different column name @Barmar
– Hozayfa
Nov 25 '18 at 19:53
add a comment |
Please, post more information about the error. You're telling is not working, but you didn't provide the error message.
– Sakura Kinomoto
Nov 25 '18 at 19:43
1
Post your code as plain text, not an image. See formatting for code formatting help.
– Barmar
Nov 25 '18 at 19:50
1
UseUNION
, not a cross product.
– Barmar
Nov 25 '18 at 19:50
Every table name has different column name @Barmar
– Hozayfa
Nov 25 '18 at 19:53
Please, post more information about the error. You're telling is not working, but you didn't provide the error message.
– Sakura Kinomoto
Nov 25 '18 at 19:43
Please, post more information about the error. You're telling is not working, but you didn't provide the error message.
– Sakura Kinomoto
Nov 25 '18 at 19:43
1
1
Post your code as plain text, not an image. See formatting for code formatting help.
– Barmar
Nov 25 '18 at 19:50
Post your code as plain text, not an image. See formatting for code formatting help.
– Barmar
Nov 25 '18 at 19:50
1
1
Use
UNION
, not a cross product.– Barmar
Nov 25 '18 at 19:50
Use
UNION
, not a cross product.– Barmar
Nov 25 '18 at 19:50
Every table name has different column name @Barmar
– Hozayfa
Nov 25 '18 at 19:53
Every table name has different column name @Barmar
– Hozayfa
Nov 25 '18 at 19:53
add a comment |
1 Answer
1
active
oldest
votes
Use a UNION
to get results from multiple tables and merge them.
SELECT name
FROM bd
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM info
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM users
WHERE name LIKE '%$query%'
If you really want to join all the tables, you need to specify the name match separately for each of them.
SELECT b.*, i.*, n.*
FROM bd AS b
CROSS JOIN info AS i
CROSS JOIN users AS u
WHERE b.name LIKE '%$query%' AND i.name LIKE '%$query%' AND u.name LIKE '%$query%'
However, this will create a cross product of all the matching rows from each table, it's hard to see how you expect this to be useful. And if any of the tables has no matching rows, that will produce an empty cross product.
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471175%2fmysql-apply-wildcards-in-multiple-table-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use a UNION
to get results from multiple tables and merge them.
SELECT name
FROM bd
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM info
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM users
WHERE name LIKE '%$query%'
If you really want to join all the tables, you need to specify the name match separately for each of them.
SELECT b.*, i.*, n.*
FROM bd AS b
CROSS JOIN info AS i
CROSS JOIN users AS u
WHERE b.name LIKE '%$query%' AND i.name LIKE '%$query%' AND u.name LIKE '%$query%'
However, this will create a cross product of all the matching rows from each table, it's hard to see how you expect this to be useful. And if any of the tables has no matching rows, that will produce an empty cross product.
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
|
show 4 more comments
Use a UNION
to get results from multiple tables and merge them.
SELECT name
FROM bd
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM info
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM users
WHERE name LIKE '%$query%'
If you really want to join all the tables, you need to specify the name match separately for each of them.
SELECT b.*, i.*, n.*
FROM bd AS b
CROSS JOIN info AS i
CROSS JOIN users AS u
WHERE b.name LIKE '%$query%' AND i.name LIKE '%$query%' AND u.name LIKE '%$query%'
However, this will create a cross product of all the matching rows from each table, it's hard to see how you expect this to be useful. And if any of the tables has no matching rows, that will produce an empty cross product.
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
|
show 4 more comments
Use a UNION
to get results from multiple tables and merge them.
SELECT name
FROM bd
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM info
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM users
WHERE name LIKE '%$query%'
If you really want to join all the tables, you need to specify the name match separately for each of them.
SELECT b.*, i.*, n.*
FROM bd AS b
CROSS JOIN info AS i
CROSS JOIN users AS u
WHERE b.name LIKE '%$query%' AND i.name LIKE '%$query%' AND u.name LIKE '%$query%'
However, this will create a cross product of all the matching rows from each table, it's hard to see how you expect this to be useful. And if any of the tables has no matching rows, that will produce an empty cross product.
Use a UNION
to get results from multiple tables and merge them.
SELECT name
FROM bd
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM info
WHERE name LIKE '%$query%'
UNION
SELECT name
FROM users
WHERE name LIKE '%$query%'
If you really want to join all the tables, you need to specify the name match separately for each of them.
SELECT b.*, i.*, n.*
FROM bd AS b
CROSS JOIN info AS i
CROSS JOIN users AS u
WHERE b.name LIKE '%$query%' AND i.name LIKE '%$query%' AND u.name LIKE '%$query%'
However, this will create a cross product of all the matching rows from each table, it's hard to see how you expect this to be useful. And if any of the tables has no matching rows, that will produce an empty cross product.
edited Nov 25 '18 at 20:15
answered Nov 25 '18 at 19:52
BarmarBarmar
429k36253353
429k36253353
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
|
show 4 more comments
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
In my three table the column name are not same but except the column name 'name'. So, UNION is not work in here.
– Hozayfa
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
You need to show the results you're trying to get.
– Barmar
Nov 25 '18 at 20:00
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
I have three tables, 'bd' table contains name, match,score.... then info table contains name, address users table contains name,email,.... . Now if I type anything in the search box for example name or address or email it will show me the output if matches.
– Hozayfa
Nov 25 '18 at 20:09
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
Show the entire result you expect from the query. Maybe you should just query each table separately and show its matching rows, instead of trying to do it in one query.
– Barmar
Nov 25 '18 at 20:10
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
That's the point. I want to know that is there any way to find out matching records from different tables which contain different column name in a single query?
– Hozayfa
Nov 25 '18 at 20:15
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471175%2fmysql-apply-wildcards-in-multiple-table-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please, post more information about the error. You're telling is not working, but you didn't provide the error message.
– Sakura Kinomoto
Nov 25 '18 at 19:43
1
Post your code as plain text, not an image. See formatting for code formatting help.
– Barmar
Nov 25 '18 at 19:50
1
Use
UNION
, not a cross product.– Barmar
Nov 25 '18 at 19:50
Every table name has different column name @Barmar
– Hozayfa
Nov 25 '18 at 19:53