phpdev@dr Posted November 20, 2009 Share Posted November 20, 2009 Hi! I need help making a php app that allow me to enter a binary number and convert it to decimal and viceversa. It will have a text box to enter the number, a drop down menu with: binary to dec and dec to binary. It will print on another page in a table the original number and the conversion. Lets say I enter: 255 ===== 11111111 Im new with php so please help! thanks, Link to comment https://forums.phpfreaks.com/topic/182323-dropdown/ Share on other sites More sharing options...
Stuie_b Posted November 20, 2009 Share Posted November 20, 2009 Php has built in functions to achieve this see here and here a quick example would be to post the text box to a php file convert using php and output to the page.. <?php $in = $_GET['bin']; if($in){ echo "Original Binary - $in -- Decimal equivilent - ".bindec($in); } ?> Stuie Link to comment https://forums.phpfreaks.com/topic/182323-dropdown/#findComment-962117 Share on other sites More sharing options...
phpdev@dr Posted November 20, 2009 Author Share Posted November 20, 2009 Thanks, I am using those two fuctions and the conversion is ok, the problem I am having is when using the dropdown menu. something I noticed is that you are using the $_get and I am using $_post, does it make a difference?, Do you then make to separate pages, one for bin to dec and another for dec to bin? could you use some if...else statement, select case or else? Please give me some example. Link to comment https://forums.phpfreaks.com/topic/182323-dropdown/#findComment-962144 Share on other sites More sharing options...
Stuie_b Posted November 20, 2009 Share Posted November 20, 2009 no GET and POST do the same job just slightly different.. the following example should get you started.. <?php $meth = $_POST['meth']; $value = $_POST['value']; if(!$meth or !$value){ ?> <form name="convertor" id="convertor" action="" method="post"> <input name="value" id="value" type="textbox" /> <select name="meth" id="meth"> <option value="1">Binary to Decimal</option> <option value="2">Decimal to binary</option> </select> <input type="submit" name="submit" id="submit" value="Convert" /> </form> <?php }elseif($meth and $value){ $out = $meth==1 ? bindec($value) : decbin($value); echo "Original Value - $value -- converted value - $out"; } ?> Stuie Link to comment https://forums.phpfreaks.com/topic/182323-dropdown/#findComment-962157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.