Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to write php MySql query
    text
    copied!<p>I would like to be able to make a selection from a select-box and view the selected table.</p> <p>My skill level with php/MySQL at this point is:</p> <pre><code>$query = "SELECT * FROM electrical ORDER BY item_id LIMIT $offset, $RPP"; </code></pre> <p>With this query the <code>div</code> is populated on page load. </p> <p>I have a select box that has 6 choices:</p> <pre><code>&lt;form&gt; &lt;select name="dbtables" onchange="showTable(this.value)" id="selectBox"&gt; &lt;option value=""&gt;Select a materials table:&lt;/option&gt; &lt;option value="" id="hr"&gt;&lt;/option&gt; &lt;option value="equipment"&gt;Worker Equipment&lt;/option&gt; &lt;option value="tool"&gt;General Tools&lt;/option&gt; &lt;option value="electrical"&gt;Electrical Materials&lt;/option&gt; &lt;option value="mechanical"&gt;Mechanical Materials&lt;/option&gt; &lt;option value="plumbing"&gt;Plumbing Materials&lt;/option&gt; &lt;option value="hvac"&gt;HVAC Materials&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; </code></pre> <p>Each choice is a table in a single MySQL database.</p> <p>Script for <code>showTable</code> is working, after making selection alert shows choice picked.</p> <pre><code>function showTable(str) { if (str == "") { document.getElementById("materials").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("materials").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "index.php?q=" + str, true); xmlhttp.send(); alert(str); } </code></pre> <p>Any pointers or help is appreciated appreciated.</p>
 

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