donglu5047 2013-03-23 09:16
浏览 52

如何使用jquery自动完成从mysql数据库加载数据?

I want to make one search box which display list of matched records from database related to which we have type in our box, I have Use Jquery's Auto Complete. That's OK, but I want to select records from my database Table instead manually give it in var availableTags. I want to get records from DB in var availableTags in following code..

here is my code with Smarty Templates.....

My Html:(searchh.tpl)

{block name=head}
    <title>Untitled Document</title>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
      <link rel="stylesheet" href="/resources/demos/style.css" />
      <script>

    }   
      $(function() {
        var availableTags = [
          "Python",
          "Ruby",
          "Scala",
          "Scheme"
        ];
        $( "#tags" ).autocomplete({
          source: availableTags     
        });
      });

      </script>
    {/block}
    {block name=body}
    <div class="ui-widget">
      <label for="tags">Tags: </label>
      <input id="tags" />
    </div>
    {/block}

My php :(searchh.php)

<?php 
    include("include/config.inc.php");
    $pArray = 0;
    $search = isset($_POST['search']) && ($_POST["search"] != "") ? $_POST['search']:''; 
    if($search != '')
    {   
      $query="select * from party where partyName like '%$search%' ";
      $result = mysql_query($query);
      $pArray = array();
      $n = 0;
      while ($row = mysql_fetch_array($result)) 
      {
        $pArray[$n]['partyId']   = $row['partyId'];
        $pArray[$n]['partyName'] = $row['partyName'];
        $n++;
      }
    }
    include("./bottom.php");
    $smarty->assign("search",$search);
    $smarty->assign("pArray",$pArray);
    $smarty->display('searchh.tpl');
    ?>

If Anybody can help, It will very grateful to me. Thanks..

  • 写回答

1条回答 默认 最新

  • doumi1852 2013-03-23 09:29
    关注

    change your url path like {$smarty.server.PHP_SELF | dirname}.balanceAj.php and you use get method in ajax function and get data using post method. If you use get method to send data (for get data $_GET[]) and Post method using (for get data $_post[])

    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了