Note that there are some explanatory texts on larger screens.

plurals
  1. POchained select ajax call only works if value is a number
    text
    copied!<p>I have the following ajax snippet that chains 2 select boxes and is populated dynamically using values found in a mysql table.</p> <p>This works great if the callType column is a numerical value like what is found in my data column SPG_CallType. When I change this to use a column that contact alphabetical letters it breaks it. I am assuming this is because the code works for just numerical values? How do I update that part of the snippet to accept either alpha or numeric?</p> <pre><code>if (isset($_GET['key'])) { $key = $_GET['key']; switch ($key) { case 'callTypeSelect': $select = new SelectBox('Repair Type?','Choose a category'); $res = mysql_query('SELECT DISTINCT SPG_CallType FROM ' . DB_TABLE . ' ORDER BY SPG_CallType ASC'); $callTypes = array(); for ($i = 0; list($callType) = mysql_fetch_row($res); $i++) { $callTypes[] = $callType; $select-&gt;addItem($callType, 'brandSelect-' . $callType); } header('Content-type: application/json'); echo $select-&gt;toJSON(); break; default: if (strpos($key, 'brandSelect-') === 0) { $callType = str_replace('brandSelect-', '', $key); $resBrands = mysql_query('SELECT SPG_Brand FROM ' . DB_TABLE . ' WHERE SPG_CallType = ' . mysql_real_escape_string($callType) . ' ORDER BY SPG_Brand ASC'); $select = new SelectBox('Choose a Manufacturer', 'Pick a brand'); for ($i = 0; list($brand) = mysql_fetch_row($resBrands); $i++) { $select-&gt;addItem($brand, 'result-' . $brand . '-' . $callType); } header('Content-type: application/json'); echo $select-&gt;toJSON(); </code></pre>
 

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