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%'");
}
}
}
}
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!And this is a sample code ( just your code ) converted to PDO. but not a right answer for your question.