Lukeishen Posted January 27, 2021 Share Posted January 27, 2021 (edited) <?php if(mysqli_num_rows($result) ) { while($row = mysqli_fetch_array($result)) { ?> <form method="POST"> <select name="inv"> <option><?php echo $row["rizikos_lygis"];?></option> <option value=<?php echo $row["sugeneruoja"]; ?>><?php echo $row["pavadinimas"];?> <?php echo $row["sugeneruoja"]; ?></option> </select> <input type="submit" name="submit" value="Apskaičiuoti"> </form> <?php } } ?> <?php if(isset($_POST['submit'])){ echo $row["sugeneruoja"]; } ?> Edited January 27, 2021 by Lukeishen Quote Link to comment https://forums.phpfreaks.com/topic/312049-how-to-echo-option-i-selected-because-right-now-it-shows-blank/ Share on other sites More sharing options...
dodgeitorelse3 Posted January 27, 2021 Share Posted January 27, 2021 (edited) Assuming you ran a query to get $result your first option has no value set. The second option should have the echo inside quotes just like your submit does. Edited January 27, 2021 by dodgeitorelse3 Quote Link to comment https://forums.phpfreaks.com/topic/312049-how-to-echo-option-i-selected-because-right-now-it-shows-blank/#findComment-1584021 Share on other sites More sharing options...
Phi11W Posted January 27, 2021 Share Posted January 27, 2021 You structure looks wrong to me. You have multiple form elements, each of which contains one select element with two option elements. I would expect there to be one form element, which contains one select element, which contains one or more option elements. echo( '<form method="POST">' ); echo( '<select name="inv">' ); if( mysqli_num_rows($result) ) { echo( '<option>' . $row["rizikos_lygis"] . '</option>' ); while( $row = mysqli_fetch_array($result) ) { printf( '<option value=\'%s\'>%s %s</option>' , $row["sugeneruoja"] , $row["pavadinimas"] , $row["sugeneruoja"] ); } } echo( '</select>' ); echo( '<input type="submit" name="submit" value="Apskaičiuoti">' ); echo( '</form>' ); Regards, Phill W. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312049-how-to-echo-option-i-selected-because-right-now-it-shows-blank/#findComment-1584022 Share on other sites More sharing options...
NotionCommotion Posted January 27, 2021 Share Posted January 27, 2021 Try this: echo 'blablabla '.$row["sugeneruoja"]; or better yet, var_dump($row["sugeneruoja"]); Forgot why, but echoing an integer by itself sometimes isn't displayed. Quote Link to comment https://forums.phpfreaks.com/topic/312049-how-to-echo-option-i-selected-because-right-now-it-shows-blank/#findComment-1584023 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.