1

我需要能够对多个表进行搜索并返回与搜索词相似的所有部分。我的问题是这些表有不同数量的列。不过,它们确实有具有相似名称的列。首先,PHP 检查“productnumber”表以查找具有相似部件号的所有部件。然后它搜索每个表以找到匹配的数字。

现在,如果在“组件”表中找到类似的部件,它将不会显示从适配器或连接器中找到的任何部件。而不是选择所有列并忽略搜索所有表,我想搜索在所有三个表中找到的这三个列并返回在所有表中找到的结果:

零件编号

图片

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%'");
        }

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

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

    }

  }

}

任何有关我的问题的帮助将不胜感激:]

4

1 回答 1

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

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

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

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

    }

您必须进行另一个循环以从结果数组中检索数据

于 2012-09-06T18:17:51.027 回答