0

我只是在学习 jQuery AutoComplete 小部件。这些值很好地用逗号弹出。因此,对用户的视觉显示很棒。

我的问题是如何将多个值保存到 MySQLi 数据库?

这是代码:

     <script>
     $(function() {
      var availableskills = [
        "ActionScript",
        "AppleScript",
         ..........
         more languages
        "XML"
    ];
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }

    $( "#skills" )
        // don't navigate away from the field on tab when selecting an item
        .bind( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "autocomplete" ).menu.active ) {
                event.preventDefault();
            }
        })
        .autocomplete({
            minLength: 0,
            // could have source as a "url"
            source: function( request, response ) {
                // delegate back to autocomplete, but extract the last term
                response( $.ui.autocomplete.filter(
                    availableskills, extractLast( request.term ) ) );
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function( event, ui ) {
                var terms = split( this.value );
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push( ui.item.value );
                // add placeholder to get the comma-and-space at the end
                terms.push( "" );
                this.value = terms.join( ", " );
                return false;
            }
        });
});
</script>

现在,这是我让用户选择技能的输入 ID:

 <div class="ui-widget">
<!--<label for="skills">Tag programming languages: </label>-->
<input type="text" id="skills" size="50" />
 </div>

不确定如何将用户选择的技能保存到数据库中。我可以轻松地将数据保存到 MySQLi 数据库;问题是我怎样才能说出三个技能并将它们保存到数据库表中的三个不同行中。

任何帮助,非常感谢。

4

1 回答 1

1

例如,您将使用输入名称技能进行表单发布

<form method="post" action="test.php">
<div class="ui-widget">
<input type="text" id="skills" size="50" name='skills' />
</div>
</form>

那么 test.php 将类似于

<?php
//...do some mysql connections
$skills = explode(",",$_POST['skills']);
foreach($skills as $skill){
    $statement.="INSERT INTO blahblahblah SET skill = ".mysqli_real_escape_string($skill);
}
$mysqli->multi_query($statement);
于 2012-12-28T01:35:21.517 回答