javascript - I want to keep on storing and displaying the result I am getting from mysql -
i not expert @ php newbie not sure do.what trying keep on saving result getting textboxthis textbox , shirt,color , price result getting table , keep on displaying on page. picture textbox attached. want keep on storing new result table , keep displaying old one. hope clear trying do. code has 3 files main file products.php has following code
<!doctype html> <html> <head> <title>products</title> <p> scan barcode of product </p> <link href="mystyle.css" rel="stylesheet"> </head> <body> <input type="text" name="enter" required id="item" style="text-align:centre" placeholder=" barcode id" autofocus /> <div id="item-data"></div> <script src="js/jquery-2.2.0.min.js"></script> <!--jquery link--> <script src="js/global.js"></script> <!--linking event file--> </body> </html>
while code global.js is
$(function(){ //press enter on text area.. $('#item').keypress(function (event) { var key = event.which; if(key == 13) // enter key code { var item = $('input#item').val(); // retreiving value item if ($.trim(item) != ''){ //send php file if empty or spaces(trim) there dont send it// $.post('ajax/name.php',{id:item}, function(data){ //using post method sending father(name.php), sending data through file item $('div#item-data').append(""+data+"</br>"); // grabing data , displaying }); } $('#item').val(''); } }); });
and third file name.php file consists of following code
<?php require '../db/connect.php'; $id= $_post['id']; // post variable $sql = "select barcodeid, shirts, price clothes barcodeid=".mysqli_real_escape_string($con,$id); $result = mysqli_query($con,$sql) or die(mysqli_error($con)); if(mysqli_num_rows($result)>0) { while($row = $result->fetch_assoc()) { echo " " . $row["barcodeid"]. " shirt color: " . $row["shirts"]. " price: " . $row["price"]; } } else { echo "id not found, please scan again"; } mysqli_close($con); ?>
this issue solved using append function in javascript. check in global.js file.
Comments
Post a Comment