penguin0 Posted June 3, 2007 Share Posted June 3, 2007 I am trying to figure the best way to automate creation of radio buttions in an edit user page. If that can be accomplished, then it would need to also go in the sql statement below, the variable declaration, and the hidden input. if ($userman || $admin == "1") { $userid = intval($_REQUEST['id']); $sql = "SELECT id, name, position, username, email, admin, pageman, userman, rateman, menuman, users, created FROM users WHERE id = $userid"; $result = mysql_query($sql, $link) or die(mysql_error()); while ( $a_row = mysql_fetch_array( $result ) ) { $id = $a_row['id']; $name = $a_row['name']; $username = $a_row['username']; $position = $a_row['position']; $uadmin = $a_row['admin']; $upageman = $a_row['pageman']; $uuserman = $a_row['userman']; $urateman = $a_row['rateman']; $umenuman = $a_row['menuman']; $uusers = $a_row['users']; $email = $a_row['email']; $created = $a_row['created']; } echo "<form action=\"do_edituser.php\" method=\"POST\"> <table cellpadding=2 cellspacing=1 class=ptable><tr><th colspan=2>Edit User: $name</th></tr> <tr><td>Name:</td><td><input type=\"text\" name=\"name\" size=\"25\" maxlength=\"25\" value=\"$name\"></td></tr> <tr><td>Position:</td><td><input type=\"text\" name=\"position\" size=\"25\" maxlength=\"35\" value=\"$position\"></td></tr> <tr><td>Username:</td><td><input type=\"text\" name=\"username\" size=\"25\" maxlength=\"25\" value=\"$username\"></td></tr> <tr><td>Email:</td><td><input type=\"text\" name=\"email\" size=\"35\" maxlength=\"50\" value=\"$email\"></td></tr> <tr><td>Created:</td><td>$created</td></tr> <input type=\"hidden\" name=\"id\" value=\"$userid\">"; } else { echo "<h3>Access Denied</h3> You do not have the necessary permissions to view this page. If you think<br /> this is an error, please contact the site administrator to gain access."; } if ($admin == "1") { echo '<tr><th colspan=2>Edit Permissions</th></tr> <tr> <td>Is Admin?</td> <td> <label> <input type="radio" name="admin" value="1" ' . ($uadmin == 1 ? 'checked="checked"' : '') . ' /> Yes <input type="radio" name="admin" value="0" ' . ($uadmin == 0 ? 'checked="checked"' : '') . ' /> No </label> </td> </tr> <tr> <td>Edit Pages?</td> <td> <label> <input type="radio" name="pageman" value="1" ' . ($upageman == 1 ? 'checked="checked"' : '') . ' /> Yes <input type="radio" name="pageman" value="0" ' . ($upageman == 0 ? 'checked="checked"' : '') . ' /> No </label> </td> </tr>'; } else { echo "<input type=\"hidden\" name=\"admin\" value=\"$uadmin\"> <input type=\"hidden\" name=\"pageman\" value=\"$upageman\"> <input type=\"hidden\" name=\"menuman\" value=\"$umenuman\"> <input type=\"hidden\" name=\"rateman\" value=\"$urateman\"> <input type=\"hidden\" name=\"userman\" value=\"$uuserman\"> <input type=\"hidden\" name=\"users\" value=\"$uusers\">"; } if ($userman || $admin == "1") { echo "<tr><td align=center colspan=2><input type=\"submit\" name=\"submit\" value=\"Update User\"></td></tr></table> </form> </td></tr>"; I need loops that where the 'id' field from table 'perms' is made into variables here: <input type="radio" name="pageman" value="1" ' . ($upageman == 1 ? 'checked="checked"' : '') . ' /> Yes <input type="radio" name="pageman" value="0" ' . ($upageman == 0 ? 'checked="checked"' : '') . ' /> No <input type=\"hidden\" name=\"pageman\" value=\"$upageman\"> $uusers = $a_row['users']; $sql = "SELECT id, name, position, username, email, admin, pageman, userman, rateman, menuman, users, created FROM users WHERE id = $userid"; any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/ Share on other sites More sharing options...
tail Posted June 3, 2007 Share Posted June 3, 2007 try using the foreach loop Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-267287 Share on other sites More sharing options...
penguin0 Posted June 3, 2007 Author Share Posted June 3, 2007 I already said I might need a loop, but I need to know how to take all the items from the id field of perms and assign it to a variable and loop it. Then I need to apply it to those 4 parts. Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-267293 Share on other sites More sharing options...
tail Posted June 3, 2007 Share Posted June 3, 2007 use a while loop to retrieve all the data from the db. itd look like: $i=0; while($result>$i) { get info $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-267296 Share on other sites More sharing options...
breath18 Posted June 3, 2007 Share Posted June 3, 2007 i would use something like this: $query = mysql_query("Your Query"); while($info = mysql_fetch_array($query) { $info[colName]; } i like this method because it converts your result into an array which is very flexable. Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-267299 Share on other sites More sharing options...
penguin0 Posted June 3, 2007 Author Share Posted June 3, 2007 Thanks, but can anyone be more specific? I don't exactly know how it would all fit together. Maybe use my code in the example? Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-267309 Share on other sites More sharing options...
tail Posted June 3, 2007 Share Posted June 3, 2007 http://www.freewebmasterhelp.com/tutorials/phpmysql/4 Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-267319 Share on other sites More sharing options...
penguin0 Posted June 7, 2007 Author Share Posted June 7, 2007 I know php format, and I know how to query, but in this case I don't know how to do what I am getting at. Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-270267 Share on other sites More sharing options...
trq Posted June 7, 2007 Share Posted June 7, 2007 You need to explain your question allot more clearly. Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-270374 Share on other sites More sharing options...
penguin0 Posted June 8, 2007 Author Share Posted June 8, 2007 Currently I am able to know what the variables I am hard coding into this: <input type="radio" name="pageman" value="1" ' . ($upageman == 1 ? 'checked="checked"' : '') . ' /> Yes <input type="radio" name="pageman" value="0" ' . ($upageman == 0 ? 'checked="checked"' : '') . ' /> No <input type=\"hidden\" name=\"pageman\" value=\"$upageman\"> $uusers = $a_row['users']; $sql = "SELECT id, name, position, username, email, admin, pageman, userman, rateman, menuman, users, created FROM users WHERE id = $userid"; but I want to make a loop with an array for future variables in this format: $upageman, with a name of pageman, but they will be named in another form and can be pulled from the id field in the perms DB. Just like id pageman is saved in perms as well. Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-270822 Share on other sites More sharing options...
penguin0 Posted June 9, 2007 Author Share Posted June 9, 2007 ? Quote Link to comment https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/#findComment-271340 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.