Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP selection based on previous selection
    primarykey
    data
    text
    <p>I have 2 functions in PHP, one of them displays the ISBN and the title of a book and the other displays the editions that exist in the database based on the ISBN selected on the previous selection.</p> <p>Here are the 2 functions:</p> <p>ISBN - Book dropdown list:</p> <pre><code> &lt;?php include ("includes/connections.php"); function dropdown($intIdField, $strNameField, $strTableName, $strOrderField, $strNameOrdinal, $strMethod="asc") { echo "&lt;select name=\"$strNameOrdinal\" onchange=\"selection($id)\"&gt;\n"; echo "&lt;option value=\"NULL\"&gt;Select Value&lt;/option&gt;\n"; $strQuery = "select $intIdField, $strNameField from $strTableName order by $strOrderField $strMethod"; $rsrcResult = mysql_query($strQuery); while($arrayRow = mysql_fetch_assoc($rsrcResult)) { $strA = $arrayRow["$intIdField"]; $strB = $arrayRow["$intIdField"] . " - " . $arrayRow["$strNameField"]; echo "&lt;option value=\"$strA\"&gt;$strB&lt;/option&gt;\n"; } echo "&lt;/select&gt;"; } ?&gt; </code></pre> <p>Edition dropdown list:</p> <pre><code>&lt;?php include ("includes/connections.php"); function dropdownEdition($intId1Field, $intId2Field, $strTableName, $strOrderField, $strNameOrdinal, $strMethod="asc") { $intId2Field = $GLOBALS['book']; var_dump($intId2Field); var_dump($_POST["book"]); echo "&lt;select name=\"$strNameOrdinal\"&gt;\n"; echo "&lt;option value=\"NULL\"&gt;Select Value&lt;/option&gt;\n"; $strQuery = "SELECT $intId1Field, $intId2Field FROM $strTableName ORDER BY $strOrderField $strMethod"; $rsrcResult = mysql_query($strQuery); while($arrayRow = mysql_fetch_assoc($rsrcResult)) { $strA = $arrayRow["$intId1Field"]; echo "&lt;option value=\"$strA\"&gt;$strA&lt;/option&gt;\n"; } echo "&lt;/select&gt;"; } ?&gt; </code></pre> <p>What I have been trying to do is pass the ISBN selected on the previous selection with a <code>onchange</code> function which would return the ISBN of the book but it failed a lot.</p> <pre><code>&lt;?php function selection($id){ echo $id; } ?&gt; </code></pre> <p>I know I'm terrible at this but I don't know what else to do if you could point me to a direction it would be much appreciated.</p> <p>I would prefer a PHP solution rather than a JavaScript one if possible.</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