0

わかりました、だから私はこれにちょっと慣れていません..私はこれからクラッドをグーグルで検索しましたが、理解していません.

説明とバーコードの2つの入力があります

説明フィールドを検索し、説明候補の選択時に説明とバーコードをオートコンプリートする必要があります。

ここに私がこれまでに持っているものがあります.PHP配列をJqueryに追加する方法がわかりません.

    <?php //My Inputs (are in a loop) *** ?>

    <input name="<?php echo 'ingdes'.$y ?>" type="text"  value="<?php  issetValue($ingdes[$y]) ?>"class="autosearch" id="<?php echo 'ingdes'.$y ?>" size="45" autocomplete='off'  /> <!-- THIS IS THE DESCRIPTION -->

     DESC

     <input name="<?php echo 'ingcode'.$y ?>" type="text" value="<?php issetValue($ingcode[$y]) ?>" class="code" id="<?php echo 'ingcode'.$y ?>" size="12"  /> 
     BARCD   <!-- THIS IS THE BARCODE -->

    <?php // End My inputs ***

          // My function ***

          public function jsAutoSearch() { ?>

          <script>
          $(function() {
          var availableTags = [ <?php

          $query= mysql_query("SELECT * FROM $this->usernameid ORDER BY name");

          while (($row = mysql_fetch_assoc($query)) !== false){
          echo '"'.$row['name'].'",';}?> 
          /* $row['barcode1'] is the additional field I need to get working and send to the other input field  */  

          ""];
          $( ".autosearch" ).autocomplete({
          source: availableTags
          });
          });
          </script>

          <?php }

          // End my function

配列での試み* ** * ****

    public function jsAutoSearch() { 

       $return_arr = array();
    $query= mysql_query("SELECT * FROM $this->usernameid ORDER BY name");

    while (($row = mysql_fetch_assoc($query)) !== false){
    $row_array['name']  = $row['name']; // THIS IS THE DESCRIPTION
    $row_array['barcode'] = $row['barcode1']; // THIS IS THE BARCODE
          array_push( $return_arr, $row_array );
    } ?>
    <script>

    $( ".autosearch" ).autocomplete({
        source: "<?php echo json_encode($return_arr),'\n'?>",
    select: function (event, ui) {
    var item = ui.item;
    if(item) {
    $(".autosearch").val(item.name); <!-- THIS IS THE DESCRIPTION -->
    $(".ingcode1").val(item.barcode); <!-- THIS IS THE BARCODE -->
    }
    ;}
    })

</script>


<?php }
4

1 に答える 1

0
     <?//*****************search.php*********************

     $searchterm = $_GET['term'];
   $return_arr = array();
$query= mysql_query("SELECT * FROM $object1->usernameid WHERE name LIKE    '%$searchterm%' ORDER BY name");

 while (($row = mysql_fetch_assoc($query)) !== false){
       $names[] = array( name => $row['name'], barcode => $row['defcode'] ) ; 
    } 


 // Cleaning up the term
$term = trim(strip_tags($_GET['term']));
// Rudimentary search
$matches = array();
foreach($names as $name){
if(stripos($name['name'], $term) !== false){
    // Add the necessary "value" and "label" fields and append to result set
    $name['value'] = $name['name'];
    $name['label'] = "{$name['name']}, {$name['defcode']}";
    $matches[] = $name;
}
  }
 // Truncate, encode and return the results
 $matches = array_slice($matches, 0, 5);
 print json_encode($matches);?>

//********************** JQuery *****************************************

       <script type="text/javascript">

     $(document).ready(function(){
var ac_config = {
    source: "search.php",
    select: function(event, ui){
        $("#ingdes<?php echo $y ?>").val(ui.item.name);
        $("#ingcode<?php echo $y ?>").val(ui.item.barcode);

    },
    minLength:1
};
$("#ingdes<?php echo $y ?>").autocomplete(ac_config);
   });
 </script>
于 2013-01-07T01:00:48.647 に答える