Jump to content

Naming a variable by the data in mysql


penguin0

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/54069-naming-a-variable-by-the-data-in-mysql/
Share on other sites

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.