dongyin0628 2017-12-11 15:53
浏览 34
已采纳

搜索结果将缩写替换为文本

I have a search form that looks up information in a SQL DB, the data has a column of abbreviations for a product type. I want to upload the data with the abbreviations and use the PHP to expand the text in the search results.

For example PF = Prefinished

Can this be done or will this slow down the search exponentially?

if ($producttype == "PF") {
    $producttype == "Prefinished"
    }
else{
  // Else
    }
  • 写回答

1条回答 默认 最新

  • dongyun6229 2017-12-11 16:05
    关注

    The first step is to put these conversions into a table where you can map between code and name, and possibly vice-versa if necessary.

    Then you can JOIN against this table to get expansions. For small tables this cost is nominal, you really won't feel it in benchmarks.

    CREATE TABLE product_types (
      id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
      code VARCHAR(255) NOT NULL,
      label VARCHAR(255) NOT NULL,
      UNIQUE KEY `index_product_types_on_code` (`code`)
    );
    

    Then populate this accordingly so you can do:

    SELECT * FROM products
      LEFT JOIN product_types ON product_types.code=products.producttype
    

    If that's a problem, though, and this data changes infrequently, you can load it in to your application layer as an associative array and map them in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序