<div class="row"> <!-- อยู่ใน loop while--> <div class="form-group col-md-4"> <label for="barcodeMachine">Barcode</label> <input type="text" class="form-control" id="barcodeMachine[]" placeholder="Enter Barcode" name="barcodeMachine[]"> </div> <div class="form-group col-md-5 col-md-offset-1"> <label for="nameMachine">ชื่อหนัง</label> <input type="text" class="form-control" id="nameMovie[]" name="nameMovie[]"> </div> </div>
<?php include 'connect.php'; try { $column = $db->prepare("SELECT * FROM tbl_material WHERE barcode = '".$_POST['barcode']."' "); $column->execute(); $Colcount = $column->columnCount(); //print("result set has $Colcount columns"); //count column 8 column $resultArray = array(); while ($row = $column->fetch(PDO::FETCH_ASSOC)) { $arrCol = array(); for ($i=0; $i<$Colcount; $i++) { $arrCol[$column->columnCount($i)] = $row[$i]; } array_push($resultArray, $arrCol); } $db = null; echo json_encode($resultArray);} } catch (PDOException $e) { echo 'ERROR: ' . $e->getMessage(); } ?>
<script type="text/javascript"> $(document).ready(function(){ $('id^="barcodeMachine').keyup(function(){ $.ajax({ url: "autofill.php" , type: "POST", data: 'barcode=' +$('id^="barcodeMachine').val() }) .success(function(result) { var obj = jQuery.parseJSON(result); if(obj == '') { $('input[type=text]').val(''); } else { $.each(obj, function(key, inval) { $('id^="barcodeMachine').val(inval["barcode"]); $('id^="nameMovie').val(inval["title"]); }); } }); }); }); </script>
Quote:autofill.php
$_POST['barcode'] = "data - test"; $column = $db->prepare("SELECT * FROM tbl_material WHERE barcode = '".$_POST['barcode']."' ");
$column = $db->prepare("SELECT * FROM tbl_material WHERE barcode = '".$_POST['barcode']."' "); $column->execute(); $Colcount = $column->columnCount(); //print("result set has $Colcount columns"); //count column 8 column
$_POST['barcode'] = "data - test"; $barcode = trim($_POST['barcode']); $column = $db->prepare('SELECT * FROM tbl_material WHERE barcode = :barcode '); $column->bindParam(':barcode', $barcode); $column->execute(); $Colcount = $column->columnCount(); //count column //print("result set has $Colcount columns");
$arrCol[$column->columnCount($i)] = $row[$i];
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง