Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This works: The jist is that the page uses ajax to call a script, which will deliver XML of the values you need, and will then populate those fields accordingly. :</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script&gt; function updateFields(itemname){ var xmlhttp; 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) { var xmlDoc=xmlhttp.responseXML; var iQdata=xmlDoc.documentElement.getElementsByTagName("ITEMQUANTITY"); var rQdata=xmlDoc.documentElement.getElementsByTagName("REMAININGQUANTITY"); var sDdata=xmlDoc.documentElement.getElementsByTagName("STOCKSDISPATCHED"); var iQ=iQdata[0].firstChild.nodeValue; var rQ=rQdata[0].firstChild.nodeValue; var sD=sDdata[0].firstChild.nodeValue; document.getElementById("itemQuantity").innerHTML=iQ; document.getElementById("remainingQuantity").innerHTML=rQ; document.getElementById("stocksDispatched").innerHTML=sD; } } xmlhttp.open("GET","quantity_script.php?itemname="+itemname,true); xmlhttp.send(); } &lt;/script&gt; &lt;form method="post" action="restore_stocks.php"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Item Name:&lt;/td&gt; &lt;td&gt;&lt;select name="itemname" onchange="updateFields(this.value)"&gt; &lt;?php $item="SELECT item_name FROM stocks"; $itemresult = @mysql_query($item)or die ("Error in query: $query. " .mysql_error()); while($row=@mysql_fetch_array($itemresult)){ echo "&lt;OPTION VALUE=".$row['item_name']."&gt;".$row['item_name']."&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Item Quantity:&lt;/td&gt; &lt;td&gt;&lt;div id="itemQuantity"&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Remaining Quantity:&lt;/td&gt; &lt;td&gt;&lt;div id="remainingQuantity"&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Stocks Dispatched:&lt;/td&gt; &lt;td&gt;&lt;div id="stocksDispatched"&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Add Stocks:&lt;/td&gt; &lt;td&gt;&lt;input name="addstocks" type="text" size="25" maxlength="25" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&lt;input type="submit" name="Submit" id="Submit" value="Restore" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And then you'd also make a script on your site "quantity_script.php" that would be something like the following:</p> <pre><code>&lt;?php //include your DB connection info $itemname=mysql_real_escape_string($_POST["itemname"]); $item="SELECT ".$itemname." FROM stocks"; $itemresult = mysql_query($item); $row=mysql_fetch_assoc($itemresult); header('Content-type: text/xml'); echo "&lt;ROOT&gt;"; echo "&lt;ITEMQUANTITY&gt;".$row["item_quantity"]."&lt;/ITEMQUANTITY&gt;"; echo "&lt;REMAININGQUANTITY&gt;".$row["rem_quantity"]."&lt;/REMAININGQUANTITY&gt;"; echo "&lt;STOCKSDISPATCHED&gt;".$row["stocks_dispatched"]."&lt;/STOCKSDISPATCHED&gt;"; echo "&lt;/ROOT&gt;"; ?&gt; </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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