javascript - Using AJAX, PHP and MySQL to display table data -


i display 1 column of data, [pin], based on [plan] , [order_id] values. plan=9 , order_id=0. load data without reloading page, using ajax.

here html/script:

<script> function showpins(str) { if (str == "") { document.getelementbyid("txthint").innerhtml = ""; return; } else { if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp = new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp = new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { document.getelementbyid("txthint").innerhtml = xmlhttp.responsetext; } } xmlhttp.open("get","getpins.php?q="+str,true); xmlhttp.send(); } } </script>  html:     <div align="center">     <h3>view pin's</h3>     <form>     <select name="users" onchange="showpins(this.value)">       <option value="">select plan type:</option>       <option value="1">plan1</option>       <option value="2">plan2</option>       <option value="3">plan3</option>       </select>     </form>     <br/>     <div id="txthint"></div>     </div> 

this php file (getpins.php):

<?php $q = intval($_get['q']);  $con = mysqli_connect('myhost','myusername','mypw','my_db'); if (!$con) {     die('could not connect: ' . mysqli_error($con)); }  mysqli_select_db($con,"my_db"); $sql="select * attpins (order_id=0, plan=9 , id = '".$q."')"; $result = mysqli_query($con,$sql);  echo "<table> <tr> <th>pin's</th> </tr>"; while($row = mysqli_fetch_array($result)) {     echo "<tr>";         echo "<td>" . $row['pin'] . "</td>";     echo "</tr>"; } echo "</table>"; mysqli_close($con); 

this based off tutorial shown here: http://www.w3schools.com/php/php_ajax_database.asp

trying make work showing correct pins plan type chosen.

your query wrong read manual where

  $sql="select * attpins (order_id=0, plan=9 , id = '".$q."')"; 

it be

 (order_id=0 , plan=9 , id = '".$q."') 

or

where (order_id=0 or plan=9 , id = '".$q."') 

according requirment


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -