html - how to show different number of records until a submit button is pressed in php -
i want if user enters name of item in text box particular details database should displayed on same page in table below. right working 1 item. if user wants select multiple items , want show record of each selected item on page until submit button not pressed. here code. appreciated.
<html> <head> <title>sales</title> <script> function search(string){ var xmlhttp; if(window.xmlhttprequest){ xmlhttp = new xmlhttprequest(); }else{ xmlhttp = new activexobject("xmlhttp"); } xmlhttp.onreadystatechange = function(){ if(xmlhttp.readystate == 4 && xmlhttp.status == 200){ document.getelementbyid("search").innerhtml = xmlhttp.responsetext; } } xmlhttp.open("get", "sales_search.php?s="+string, true); xmlhttp.send(null); } </script> </head>
i have not included css code shorten it.
<?php include "connection.php"; function sales_result() { $submit = $_get['finish']; if(isset($_get['mname']) && $_get['mname'] != '') { $name = $_get['mname']; $sql = "select * `medicine_item_record` `medicine_item_name` '%$name%'"; $result = mysqli_query($globals['link'],$sql); $row = mysqli_fetch_assoc($result); while($check =='submit') { echo strtoupper($row['company_name']); } } } ?> <body> <div style="text-align: center; width: 500px; margin: 0 auto;"> <h1>sales</h1><span style="font-family: tahoma, sans-serif, arial; margin-left: 150px; font-size: 13px;"></span><br/><br/> <table border=1> <tr><td><input type="text" placeholder="type search.." onkeyup="search(this.value)" id="text" ></td> <td><input type="text" placeholder="enter quantity" name="quantity" id="text"></td> <td><input type ="submit" name="finish" value="finish"></td> </tr> </table> <div id="search"> </div> </div> <table border=1 width='100%' align= 'center'> <tr><?php sales_result() ?> </tr> </table> </body> </html>
code sales_search.php follows:
<?php include "connection.php"; if(isset($_get['s']) && $_get['s'] != '') { $s = $_get['s']; $sql = "select * `medicine_item_record` `medicine_item_name` '%$s%'"; $result = mysqli_query($link,$sql); while($row = mysqli_fetch_array($result)) { $name = $row['medicine_item_name']; echo "<div style='' id='searchtitle'>"."<a style='font-family: verdana; text-decoration: none; color: black;' href='sales.php?mname=$name'>" . $name . "</div>"; } } ?>
not sure mean multiple items. taking stab mean if user enters different search terms? example: "depressor, swab". need parse in way before building query. if separator (my example it's comma) in string, explode , make query using loop:
<?php include "connection.php"; if(isset($_get['s']) && $_get['s'] != ''){ $search_str = trim($_get['s']); if(strpos($search_str, ",")){ // multiple search terms found $s = explode($search_str, ","); $sql = "select * `medicine_item_record` `medicine_item_name` '%" . mysqli_real_escape_string(trim($s[0]), $con) . "%'"; for($i=1;$i<count($s);$i++){ $sql .= " or `medicine_item_name` '%" . mysqli_real_escape_string(trim($s[$i]), $con) . "%'"; } $sql .= ";"; } else { $sql = "select * `medicine_item_record` `medicine_item_name` '%" . mysqli_real_escape_string($search_str, $con) . "%';"; } $result = mysqli_query($link,$sql); while($row = mysqli_fetch_array($result)){ $name = $row['medicine_item_name']; echo "<div style='' id='searchtitle'>"."<a style='font-family: verdana; text-decoration: none; color: black;' href='sales.php?mname=$name'>" . $name . "</div>"; } } ?>
edit after comment:
that happening in response of ajax call:
document.getelementbyid("search").innerhtml = xmlhttp.responsetext;
this line of code replaces content in element. want append response:
var current = document.getelementbyid("search").innerhtml; document.getelementbyid("search").innerhtml = current + xmlhttp.responsetext;
Comments
Post a Comment