0

How do I set a variable in mysql database to equal txt so for example I have a table user-status which has values of 0 , 1, 2 or 3. I want a drop down to say if user_status = 3 display admin if user_status = 0 display no status in the drop down and so on. Here is my code

<?php
    $SESSION_ID = ($_POST['SESS_MEMBER_ID']);
	require_once('auth.php');
	require_once('config.php');
	
		//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	
		
	//Create query
	
$sqlid= $_SESSION['SESS_MEMBER_ID']; 
$my_rows;
$sql = mysql_query("SELECT * FROM members order by member_id");
if(!$sql) {
		die("Unable to select query");
	}

while($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
	$my_rows = $my_rows . '<br><br />
Member ID: &nbsp;' . '<a href="?edit='.$row['member_id'] .'">' . $row['member_id'] . '</a>' . '<br />
Name:<b> ' . $row['firstname'] . ' ' . $row['lastname'] . '</b><br />
Login: ' . $row['login'] . ' <br />
Password: ' . $row['passwd'] . '  <br />
Member Status: ' . $row['user_status'] . ' <br />';
$id = $row['member_id'];
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Admin</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Welcome <?php echo $_SESSION['SESS_FIRST_NAME'];?> <?php echo $_SESSION['SESS_LAST_NAME'];?>

</h1>
<a href="member-profile.php">My Profile</a> | <a href="logout.php">Logout</a>
<p><br /></p>
<p>Current List of members</p>
<p>Anyone with a status of Admin can see this Page</p>

<?php echo   $my_rows  ?>
</p>
</body>
</html>

Edited by freshfitz: n/a

2
Contributors
7
Replies
10
Views
7 Years
Discussion Span
Last Post by damnpoet
0

could you please try explain what you need a little more. I don't follow... you need a dropdown that shows which status a user has assigned, but status value is a numeric one (1,2) instead of a string ('admin', 'editor') ?? is that what you need?

0

yes the status in the database is 0 or 1 or 2 or 3 if I php echo $row I get an output of 1 2 or 3. I want it to display some sort of text like admin user super admin. Can I make a variable? like $status = if $row == 0 'no access elseif $row == 1 standard user elseif $row ==2 admin elseif $row ==3 super admin?

0

try this:

<?
$status = $row['user_status'];

switch($status){
     case 0: echo "admin"; break;
     case 1: echo "user"; break;
     case 2: echo "super admin"; break;
}
0

It's weird I changed it to the code below but when I output the database loop it still displays the numeric value for status but at the top of the page I get admin,user,superuser

$sqlid= $_SESSION['SESS_MEMBER_ID']; 
$my_rows;
$sql = mysql_query("SELECT * FROM members order by member_id");
  
if(!$sql) {
		die("Unable to select query");
	}
while($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
$status = $row['user_status'];

switch($status){
     case 0: echo "admin"; break;
     case 1: echo "user"; break;
     case 2: echo "super admin"; break;
}
	$my_rows = $my_rows . '<br><br />
Member ID: &nbsp;' . '<a href="?edit='.$row['member_id'] .'">' . $row['member_id'] . '</a>' . '<br />
Name:<b> ' . $row['firstname'] . ' ' . $row['lastname'] . '</b><br />
Login: ' . $row['login'] . ' <br />
Password: ' . $row['passwd'] . '  <br />
Member Status: ' . $status . ' <br />';
$id = $row['member_id'];
}
?>

php echo $my_rows gives me this

Member ID: 2
Name: Tom Jones
Login: rover
Password: 81dc9bdb52d04dc20036dbd8313ed055
Member Status: 3

0

try this:

$sqlid= $_SESSION['SESS_MEMBER_ID']; 
$my_rows;
$sql = mysql_query("SELECT * FROM members order by member_id");
  
if(!$sql) {
		die("Unable to select query");
	}
while($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
$status = $row['user_status'];

$statusStr = NULL;
switch($status){
     case 0: { $statusStr = "admin"; break; }
     case 1: { $statusStr = "user"; break; }
     case 2: { $statusStr = "super admin"; break; }
}

$my_rows = $my_rows . '<br><br />
Member ID: &nbsp;' . '<a href="?edit='.$row['member_id'] .'">' . $row['member_id'] . '</a>' . '<br />
Name:<b> ' . $row['firstname'] . ' ' . $row['lastname'] . '</b><br />
Login: ' . $row['login'] . ' <br />
Password: ' . $row['passwd'] . '  <br />
Member Status: ' . $statusStr . ' <br />';
$id = $row['member_id'];
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.