Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display MYSQL record using a combobox in PHP/AJAX?
    primarykey
    data
    text
    <p>Need help. I using 3 tables to store booking information: <code>eventinfo</code>, <code>customer</code> and <code>testbook</code> and I try to display records by using combo box to sort by username and eventID. </p> <p>Problem is the combobox does not load data from database.</p> <p>My code: </p> <p><strong>index.php</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4./jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;select name="users" onchange="showUser(this.value)"&gt; &lt;option selected="selected"&gt;--Select user--&lt;/option&gt; &lt;?php include('db.php'); $sql=mysql_query("select username, custNo from testbook"); while($row=mysql_fetch_array($sql)) { $id=$row['custNo']; $username=$row['username']; echo '&lt;option value="'.$id.'"&gt;'.$username.'&lt;/option&gt;'; } ?&gt; &lt;/select&gt; &lt;/form&gt; &lt;br /&gt; &lt;div id="txtHint"&gt;&lt;b&gt;Person info will be listed here.&lt;/b&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>getuser.php</strong></p> <pre><code>&lt;?php $q=$_GET["q"]; $con = mysql_connect('localhost', '', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("eventdb", $con); $sql="SELECT * FROM testbook WHERE custNo = '".$q."'"; $result = mysql_query($sql); echo "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Booth&lt;/th&gt; &lt;th&gt;Event&lt;/th&gt; &lt;th&gt;Date&lt;/th&gt; &lt;th&gt;Status&lt;/th&gt; &lt;th&gt;Booking ID&lt;/th&gt; &lt;/tr&gt;"; while($row = mysql_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['boothAlias'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['eventID'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['date'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['bstatus'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['bookingID'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysql_close($con); ?&gt; </code></pre> <p>Output:</p> <p><img src="https://i.stack.imgur.com/6beyv.jpg" alt="output"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload