thecase Posted August 6, 2010 Share Posted August 6, 2010 Hi, This is part of my table code echo "<td align=\"center\"><font color=\"{$colors[$row['presenter1status']]}\">{$row['presenter1']}</font> <input type='checkbox' /></td>"; Now what I was hoping to do is write some code to check what is selected and what isnt to be then able to write some queries to the database. Can anyone give any pointers Thanks Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/ Share on other sites More sharing options...
will35010 Posted August 6, 2010 Share Posted August 6, 2010 Look at the isset and empty functions. http://www.php.net/manual/en/function.empty.php http://us.php.net/manual/en/function.isset.php Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/#findComment-1096075 Share on other sites More sharing options...
thecase Posted August 6, 2010 Author Share Posted August 6, 2010 I know this but the problem is there will be like 50 records with 50 checkboxs so how can I define all 50 of them Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/#findComment-1096081 Share on other sites More sharing options...
will35010 Posted August 6, 2010 Share Posted August 6, 2010 I know this but the problem is there will be like 50 records with 50 checkboxs so how can I define all 50 of them On your html, set the name for the checkboxes the same and the value something unique. Then you only have to check one. Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/#findComment-1096083 Share on other sites More sharing options...
thecase Posted August 6, 2010 Author Share Posted August 6, 2010 On your html, set the name for the checkboxes the same and the value something unique. Then you only have to check one. So if the user selects 10 out of the 50 checkboxes will all the same name im not sure how I can take the selected data and input it into the database for example if checked update table users feild admin and make it 1. Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/#findComment-1096087 Share on other sites More sharing options...
will35010 Posted August 6, 2010 Share Posted August 6, 2010 On your html, set the name for the checkboxes the same and the value something unique. Then you only have to check one. So if the user selects 10 out of the 50 checkboxes will all the same name im not sure how I can take the selected data and input it into the database for example if checked update table users feild admin and make it 1. I see what your saying, but I'd really have to see your code. It really depends on how it's written to see how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/#findComment-1096089 Share on other sites More sharing options...
sinista Posted August 7, 2010 Share Posted August 7, 2010 could you do something like this? <?php #with something like this you could have 100 individualy names checkboxes #and only process the valid few if(!empty($_REQUEST['submit'])){ #have a look at all the requests print_r($_REQUEST); echo "<br /><br />"; $total =0; #look at each request foreach($_REQUEST as $a) { #if the request has a * in it if(strpos($a,'*')) { #chop it into two parts $b = explode('*',$a); #if the first part is SELECTME if($b[0] = 'SELECTME'); { #increment total buy part 2 (the intended value from the check box) #or other do syuff code #i.e. $sql ="insert into table_name(total) values('$b[1]')"; $total = $total + $b[1]; } } } echo "total: ".$total; } ?> <form name="form1" action="?" method="post"> <?php for($i=0; $i<=9; $i++){ ?> <input name="check<?php echo $i;?>" type="checkbox" value="SELECTME*10" /> <?php } ?> <input type="submit" name="submit" value="go" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/210002-checkbox/#findComment-1096226 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.