dongshu9458 2012-06-05 21:27
浏览 37
已采纳

用PHP构建搜索脚本

I'm trying to build a search script in PHP-SQL something like Facebook or Stackoverflow uses. For example, the user may put in multiple entries; separated by a semi-colon and with Autocomplete on each term. Also: the values are to be stored in SQL; so what type of data should I use or how I should insert those terms in SQL table??

<script type="text/javascript">
 $().ready(function() {
 $("#job_type").autocomplete("get_job_list.php",
 { width: 224, matchContains: true, selectFirst: false }); });
 </script>

PHP code::

<?php 
require_once "connection.php";
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select DISTINCT itemid as itemid from eportal where itemid LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
    $cname = $rs['itemid']; echo "$cname
"; 
} 
?>
  • 写回答

1条回答 默认 最新

  • dongtangu8403 2012-06-05 21:45
    关注

    Add chosen tags separated into a table with structure query_id tag_id (you will also need a table tags with a structure tag_id tag_name. This way your query will be way easier and faster. Moreover, you will be able to get something like most popular tags easily. SQL is meant for storing data like that. Putting comma separated values is against the basics of SQL.

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

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题