chuddyuk Posted March 14, 2006 Share Posted March 14, 2006 Im making a news system with catergories. my database lists these catergories. and in the record if there is a "1" in for example the business news record then that is the chosen catergory which means the rest will have "0"s.i want to input the data now through a form not manually into the records.im just getting stuck with how to make it add the "1" when the radio button is selected and submited any ideas?the catergories and wat they are called in the database are:::[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Name = database feild nameBusiness = businessStudent Union = suEmployer News = employers16 - 19 Years = sixteenAdult News = adults[/quote] thanks in advance for any help!! Quote Link to comment Share on other sites More sharing options...
XenoPhage Posted March 14, 2006 Share Posted March 14, 2006 [!--quoteo(post=354865:date=Mar 14 2006, 08:03 AM:name=chuddyuk)--][div class=\'quotetop\']QUOTE(chuddyuk @ Mar 14 2006, 08:03 AM) [snapback]354865[/snapback][/div][div class=\'quotemain\'][!--quotec--]im just getting stuck with how to make it add the "1" when the radio button is selected and submited any ideas?[/quote]I'm not 100% sure of what you want.. Post what code you currently have, as well as the database design, and maybe we can help more.. As for how to detect if a radio button is selected, you need to do something like this :[code]<input type='radio' name='newstype' value='1'>Business</input><input type='radio' name='newstype' value='2'>Student Union</input><input type='radio' name='newstype' value='3'>Employer News</input><input type='radio' name='newstype' value='4'>16-19 Years</input><input type='radio' name='newstype' value='5'>Adult News</input>[/code]And then on the php side :[code]if ($_REQUEST['newstype'] == 1) { // Handle business news here} else if ($_REQUEST['newstype'] == 2) { // Handle student union news here} else if ($_REQUEST['newstype'] == 3) { // Handle employer news here} else if ($_REQUEST['newstype'] == 4) { // Handle 16-19 years news here} else if ($_REQUEST['newstype'] == 5) { // Handle adult news here} else { // Handle exceptions here (nothing was chosen!)}[/code] Quote Link to comment Share on other sites More sharing options...
insrtsnhere13 Posted March 14, 2006 Share Posted March 14, 2006 im pretty sure he wants something like this..[code]<input type='radio' name='business' value='1'>Business</input><input type='radio' name='su' value='1'>Student Union</input><input type='radio' name='employer' value='1'>Employer News</input><input type='radio' name='sixeen' value='1'>16-19 Years</input><input type='radio' name='adultnews' value='1'>Adult News</input>[/code]And then on the php side :[code]if ($_REQUEST['business'] == 1) { update the database saying they want that news} else { leave it as a zeo }if ($_REQUEST['su'] == 1) { update the database saying they want that news} else { leave it as a zeo }if ($_REQUEST['employer'] == 1) { update the database saying they want that news} else { leave it as a zeo }if ($_REQUEST['sixteen'] == 1) { update the database saying they want that news} else { leave it as a zeo }if ($_REQUEST['adultnews'] == 1) { update the database saying they want that news} else { leave it as a zeo }[/code] Quote Link to comment Share on other sites More sharing options...
jmag Posted March 14, 2006 Share Posted March 14, 2006 The post by insrtsnhere13 isn't actually accurate, since if you name the radiobuttons diffrently they may all be selected. Then you may as well use checkboxes.Radios are supposed to have the same name, and then you can assign them a value like so:[code]<input type='radio' name='newstype' value='1'>Business</input><input type='radio' name='newstype' value='2'>Student Union</input><input type='radio' name='newstype' value='3'>Employer News</input><input type='radio' name='newstype' value='4'>16-19 Years</input><input type='radio' name='newstype' value='5'>Adult News</input>[/code]then I'd suggest you have a column in the database table called "newstype" for example with datatype Enum. Enumerated values are predefined when you create the table by yourself, which means you can say that this column in the database only accepts the values 1, 2, 3, 4 and 5. ([a href=\"http://dev.mysql.com/doc/refman/4.1/en/enum.html\" target=\"_blank\"]read all about enum here[/a])When pulling data from the table you know for instance that 1 is business etc. This also means you can take the values directly from the radiobutton and insert it into the database, no if-statement or nothing required... 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.