vidyashankara Posted June 8, 2006 Share Posted June 8, 2006 I have a variable $chain. Lets say the value of $chain is 3. I want 3 checkboxes to show up with different values.If $chain =3 then,[code]<input type=checkbox name=chain value=a><input type=checkbox name=chain value=b><input type=checkbox name=chain value=c>[/code]If $chain =4 then,[code]<input type=checkbox name=chain value=a><input type=checkbox name=chain value=b><input type=checkbox name=chain value=c><input type=checkbox name=chain value=d>[/code]how do i do that? Quote Link to comment https://forums.phpfreaks.com/topic/11510-form-actions-with-php/ Share on other sites More sharing options...
poirot Posted June 8, 2006 Share Posted June 8, 2006 This will do:[code]<?php$alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); $chain = 4;for ($i=0; $i<$chain; $i++) { echo '<input type="checkbox" name="chain[]" value="' . $alpha[$i] . '">' . "\n";}?>[/code]Obviously this limits $chain to 26, so I would rather use numbers. Quote Link to comment https://forums.phpfreaks.com/topic/11510-form-actions-with-php/#findComment-43307 Share on other sites More sharing options...
.josh Posted June 8, 2006 Share Posted June 8, 2006 i assume that, like everybody else who posts about this, you have a list of stuff in a database and you want to list the stuff with a checkbox next to each one. [code]$sql = "select * from table";$rs = mysql_query($sql);while ($list = mysql_fetch_array($rs)) { echo "<input type='checkbox' name='blah[]' value='" . $list['value'] . "'>" . $list['whatever'] . "<br>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11510-form-actions-with-php/#findComment-43311 Share on other sites More sharing options...
vidyashankara Posted June 8, 2006 Author Share Posted June 8, 2006 [!--quoteo(post=381516:date=Jun 8 2006, 02:17 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 02:17 PM) [snapback]381516[/snapback][/div][div class=\'quotemain\'][!--quotec--]This will do:[code]<?php$alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); $chain = 4;for ($i=0; $i<$chain; $i++) { echo '<input type="checkbox" name="chain[]" value="' . $alpha[$i] . '">' . "\n";}?>[/code]Obviously this limits $chain to 26, so I would rather use numbers.[/quote]Thanks dude. For some reason it dint work at first. Then i simply put the echo line and the array line without the rest and it worked! :) Thanks a bunch! Quote Link to comment https://forums.phpfreaks.com/topic/11510-form-actions-with-php/#findComment-43345 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.