php method to implement the secondary linkage menu: first, according to the value of the large category, pass the value to the background PHP for processing through jQuery; then use PHP to query the MySQl database to get the corresponding small category; finally return the JSON data to Just front-end processing.
Recommended: "PHP Video Tutorial"
jq php mysql realizes secondary menu linkage
Secondary linkage drop-down menu selection is used in many places, such as province and city drop-down linkage, and product size drop-down selection linkage.
The effect achieved is that when a major category is selected, the option content in the small category drop-down box also changes accordingly. Implementation principle: According to the value of the major category, the value is passed to the background PHP for processing through jQuery. PHP queries the MySQl database to obtain the corresponding small category and returns JSON data to the front-end for processing.
html:
<label>大类:</label> <select name="bigname" id="bigname"> <option value="1">前端技术</option> <option value="2">程序开发</option> <option value="3">数据库</option> </select> <label>小类:</label> <select name="smallname" id="smallname"> </select>
jQuery
<script> $(function(){ getSelectVal(); $("#bigname").change(function(){ getSelectVal(); }); }) function getSelectVal(){ $.getJSON("server.php",{bigname:$("#bigname").val()},function(json){ var smallname = $("#smallname"); $("option",smallname).remove(); $.each(json,function(index,array){ var option = "<option > > value='"+array['id']+"'>"+array['title']+"</option>"; smallname.append(option); }); }); } </script>
php Obtaining data is to obtain small categories from the database based on the id of the large category, and then return it in json format.
The above is the detailed content of PHP implements secondary linkage menu. For more information, please follow other related articles on the PHP Chinese website!