ArunC Posted April 22, 2020 Share Posted April 22, 2020 (edited) Hi All, I am trying create 4 dropdowns and load the values based on the value selected in the previous dropdown. I am able to do this for 3 dropdowns, but for the fourth dropdown I am no able to populate the value. Could someone help me out with this please? --------------------------------------- ajaxData_1.php <?php // Include the database config file include_once 'dbconfig_1.php'; if(!empty($_POST["solutions_id"])){ // Fetch state data based on the specific country $query = "SELECT * FROM releases WHERE solutions_id = ".$_POST['solutions_id']; $result = $db->query($query); if($result->num_rows > 0){ echo '<option value="">Select release</option>'; while($row = $result->fetch_assoc()){ echo '<option value="'.$row['releases_id'].'">'.$row['releases_name'].'</option>'; } } else{ echo '<option value="">Release not available</option>'; } } elseif(!empty($_POST["releases_id"])){ $query = "SELECT * FROM versions WHERE releases_id = ".$_POST['releases_id'].""; $result = $db->query($query); if($result->num_rows > 0){ echo '<option value="">Select version</option>'; while($row = $result->fetch_assoc()){ echo '<option value="'.$row['version_id'].'">'.$row['supported_version'].'</option>'; } } else{ echo '<option value="">Version not available</option>'; } } elseif(!empty($_POST["versions_id"])) { $query = "SELECT * FROM platforms WHERE version_id = ".$_POST['version_id'].""; $result = $db->query($query); if($result->num_rows > 0){ echo '<option value="">Select Version</option>'; while($row = $result->fetch_assoc()){ echo '<option value="'.$row['platforms_id'].'">'.$row['platforms_name'].'</option>'; } } else{ echo '<option value="">Platform not available</option>'; } } ?> <?php if(isset($_POST['submit'])) { echo 'Selected Solution ID: '.$_POST['solution']; echo 'Selected Release ID: '.$_POST['release']; echo 'Selected Version ID: '.$_POST['version']; echo 'Selected Platform ID: '.$_POST['platform']; } ?> Index_3.php <!DOCTYPE html> <html> <head> <title style="color: 000000">Solution Compatibility Matrix</title> <style> select { padding: 12px; min-width:280px; margin-top:10px; } .san{ width:280px; margin:0 auto; margin-top:90px; background-color:#FFFFFF; padding:55px; color: 000000; } label { color:#000000; margin-bottom:25px; } html{ background-color: #3399CC; } </style> </head> <body> </body> </html> Thanks, Arun Edited April 23, 2020 by cyberRobot Added code tags Quote Link to comment Share on other sites More sharing options...
requinix Posted April 22, 2020 Share Posted April 22, 2020 Where's the rest of the code? 1 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted April 23, 2020 Share Posted April 23, 2020 Also, please use code tags when posting code to the forum. It makes the post much easier to read. One way to add code tags is to click the <> icon in the toolbar above the area where you are writing the post. It's right next to the smiley face. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 23, 2020 Share Posted April 23, 2020 I will admit I'm somewhat mystified as to what you are going for here. You have these queries separated via a chained if - then elseif which is somewhat odd. With that said, we don't have the markup for the select attribute, which is where I would guess the problem lies. I don't know if you are rendering it with javascript, but it's a pretty good guess that you have a naming issue for the 3rd query, where the name of the select is not named correctly. Your diagnostic at the bottom should have revealed that. $query = "SELECT * FROM platforms WHERE version_id = ".$_POST['version_id'].""; Another possible issue is that the table structure is incorrect or there is no data in the platforms table that matches the criteria. Again, we don't know what your database class actually does, or if it has any error checking for SQL errors since all we have is wrapper code like this: $result = $db->query($query); Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 23, 2020 Share Posted April 23, 2020 One other more general comment, but the way you have named your script implies you are either currently or planning to load data via ajax. Ajax will be a lot easier to work with if you return your data as json, and generate your markup code for the options in your clientside scripts, rather than echoing partial html. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.