digitalgod Posted July 31, 2006 Share Posted July 31, 2006 he guys,I have a dynamic form that displays users and their level of validation. I was wondering how would I add a checkbox to confirm the level of validation (which is in a drop down) so that I can select as many users as I want and when I click on validate, it validates their level? The checkbox needs to contain the username and the level that was chosen in the dropdown (I think)here's what I have so far[code]<form action="admin.php?a=viewusers&action=validate" method="post" name="validate" id="validate"> <input type="hidden" name="process_b" value="yes"> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div> <?php if (!isset($_SESSION['custom_browse']) && !isset($_GET['action'])) { $browse = mysql_query("SELECT * FROM mtlguest_users WHERE level='2' ORDER BY id DESC") or die(query_error()); } if (isset($_SESSION['custom_browse']) && !isset($_GET['action'])) { $browse = $_SESSION['custom_browse']; } if (!isset($_SESSION['custom_browse']) && isset($_GET['action'])) { $browse = $_SESSION['all_validate']; } while ( $row = mysql_fetch_array($browse)) { echo ' <div style="margin-left:9px; margin-top:7px; width:354px "> <div>Username: <strong>'.$row['username'].'</strong></div> <div>Last Name: <strong>'.ucfirst($row['lname']).'</strong></div> <div>First Name: <strong>'.ucfirst($row['fname']).'</strong></div> <div>Age: <strong>'.age($row['date_birth']).'</strong></div> <div>Sexe: <strong>'.ucfirst($row['gender']).'</strong></div> <div>Location: <strong>'.$row['city'].'</strong></div> <div>Active: <strong>'.$row['active'].'</strong></div>'; if ($browse != $_SESSION['all_validate']) { echo '<div>Level of validation: <strong>'.$row['validation'].'</strong></div>'; } else { echo '<div>Level of validation: <select name="valid_lvl" id="valid_lvl" style="width:40px; height:12px; font-family:tahoma; font-size:10px; color:#9A400C "> <option>Choose one</option>'; foreach ($aValid as $val) { echo "<option value='$val'"; if ($val==$row['validation']) { echo " selected"; } echo ">".$val; }echo '</select> Validate: <input type="checkbox" name="validation[]" value=""> </div>'; } echo '<div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div> </div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>'; } ?> </form>[/code]I hope I was clear enough Quote Link to comment Share on other sites More sharing options...
onlyican Posted July 31, 2006 Share Posted July 31, 2006 You can doinput type='checkbox' name='validate[]' value='IDNUMBER'>Using [] makes the result in an arrayand changing IDNUMBERwith the unique number from the databaseThen you can run a query$validate = $_POST["validate"];$num_array = count($validate);for($i = 0; $i < $num_array; $i++){$query = "UPDATE QUERY WHERE IDNUMBER = ".$validate[$i]."}Remember arrays start at 0counting starts at 1so if the array had 5 results, the count would be 5, the result would be01234 Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 thanks onlyican but how do I grab the value of the drop down at the same time, so if for one entry I choose level 3 in the drop down and check the validate checkbox, how do I associate that level to that id? Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 would using a 2d array work?? something like grabbing the id of what has been checked and the level at the same? not sure how to do it though Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 something like validate[$level][]?? Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 where $level would be the value of the drop down? I'm really not sure how to accomplish this, the values that have to be stored in the array would be the id of the user and the chosen level but those values are only stored if I checked "validate" so if I have 5 entries and I only select 3 of them the array would likeArray( [2] => 0 [4] => 3 [5] => 5) where the first part is the id number and the second part is the level. Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 you can do something like <input type='checkbox' name='validate[$level]' value='$value'>do you have the users' level information when you construct the checkbox? Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 well their default level is 0 but I want to be able to change that with a drop down but I want to be able to keep some users at level 0 so if the level is 0 in the drop down and I check validate it will "confirm" his level.Trying to make this as clear as possible...If I have a list of 100 users, I want to validate them by choosing the level and checking the checkbox next to the drop down, so if I select level 3 in the drop down and check the box it will update his level and add "true" to validated.so far this is what I have to process the form[code=php:0]$validate = $_POST['validate'];$num_array = count($validate);for ($i=0; $i < $num_array; $i++) {$query = "UPDATE " . $prefix . "users SET validation='$validation',validated='true' WHERE id = ".$validate[$i]."";$result = mysql_query($query) or die(query_error());}[/code]what I'm missing is the $validation (which is the level) Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 so the layout is this?[code]USER DROPDOWN CHECKBOXUSER DROPDOWN CHECKBOX[/code] Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 well here I'll show you the form[code]<form action="admin.php?a=viewusers&action=validate" method="post" name="validate" id="validate"><input type="hidden" name="process_b" value="yes"><div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div><?php if (!isset($_SESSION['custom_browse']) && !isset($_GET['action'])) {$browse = mysql_query("SELECT * FROM users WHERE level='2' ORDER BY id DESC") or die(query_error());}if (isset($_SESSION['custom_browse']) && !isset($_GET['action'])) {$browse = $_SESSION['custom_browse'];}if (!isset($_SESSION['custom_browse']) && isset($_GET['action'])) {$browse = $_SESSION['all_validate'];}while ( $row = mysql_fetch_array($browse)) {echo '<div style="margin-left:9px; margin-top:7px; width:354px "><div>Username: <strong>'.$row['username'].'</strong></div><div>Last Name: <strong>'.ucfirst($row['lname']).'</strong></div><div>First Name: <strong>'.ucfirst($row['fname']).'</strong></div><div>Age: <strong>'.age($row['date_birth']).'</strong></div><div>Sexe: <strong>'.ucfirst($row['gender']).'</strong></div><div>Location: <strong>'.$row['city'].'</strong></div><div>Active: <strong>'.$row['active'].'</strong></div>';if ($browse != $_SESSION['all_validate']) {echo '<div>Level of validation: <strong>'.$row['validation'].'</strong></div><div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div></div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>';} else {echo '<div>Level of validation: <select name="valid_lvl" id="valid_lvl" style="width:40px; height:12px; font-family:tahoma; font-size:10px; color:#9A400C "><option>Choose one</option>';foreach ($aValid as $val) {echo "<option value='$val'";if ($val==$row['validation']) { echo " selected"; }echo ">".$val;}echo '</select> Validate: <input type="checkbox" name="validate[]" value="'.$row['id'].'"></div><div style="margin-top:7px " align="right"><a href="#" class="light_gray" style="text-decoration:none "><strong>view profile </strong></a></div></div> <div style="margin-left:8px; margin-top:10px; margin-right:8px; height:1px; background-image:url(images/dot.jpg) "><img src="images/spacer.gif"></div>'; }}echo '<div style="margin-top:10px"><input type="submit" name="Submit" value="Validate"></div>';?></form>[/code]the reason I want a checkbox is because I don't want to validate everyone in 1 shotsorry about the formating but whenever I copy and paste from dreamweaver everything is weird Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 ok you can use[code]<select name="valid_lvl[$row[id]]">[/code] Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 and how do I process it? Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 [code]<?php$validate = $_POST['validate'];$num_array = count($validate);for ($i=0; $i < $num_array; $i++) { $id = $validate[$i]; $query = "UPDATE " . $prefix . "users SET validation='" .$valid_lvl[$id]. "',validated='true' WHERE id = ".$id.""; $result = mysql_query($query) or die(query_error());}?>[/code] Quote Link to comment Share on other sites More sharing options...
digitalgod Posted August 1, 2006 Author Share Posted August 1, 2006 perfect! thank you so much 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.