snallemap Posted September 23, 2010 Share Posted September 23, 2010 Alright, so i've decided to just call some of the things in my MySQL for numbers because i decided that in the future i will turn that number into a text... Now i have been looking a bit at it, but im not quite sure how to do... Im looking to create a code so that if status is = 1 then status should appear as: member if status is = 2 then status should appear as: donator if status is = 3 then status should appear as: admin if status if = 4 then status should appear as: super admin Now the problem is just that, i keep making errors, so now im asking you for help. - Status is a field in my user database Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 23, 2010 Share Posted September 23, 2010 Please post your code and any error messages you're getting. Ken Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 I don't have a code since i couldn't figure how to set it up when you gotta get the database info and then turn that into a text .... I were hoping you could tell me how to do Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 Get a field from the database through a select statement: http://www.w3schools.com/sql/sql_select.asp And then use a case statement to get it to echo out the text you want, or to save a second variable to that specific text: http://php.net/manual/en/control-structures.switch.php Quote Link to comment Share on other sites More sharing options...
Andy-H Posted September 23, 2010 Share Posted September 23, 2010 //query user table, pull `status` field $status = array(1 => 'Member', 'Donator', 'Admin', 'Super Admin'); echo $status[$arr['status']]; Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 <?php include "config.php"; $status = "SELECT status FROM gusers" if ($status == 0) { echo "Member"; } elseif ($status == 1) { echo "Admin"; } elseif ($status == 2) { echo "Super Admin"; } ?> It says there is an error on line 6.... Whats the problem with it Please help. Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 //query user table, pull `status` field $status = array(1 => 'Member', 'Donator', 'Admin', 'Super Admin'); echo $status[$arr['status']]; This didn't seem to work for me Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 What's the error code? (Are you reading ANY of our replies? I believe this is the 3rd thread of MULTIPLE people asking you for the error MESSAGE) Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 What's the error code? (Are you reading ANY of our replies? I believe this is the 3rd thread of MULTIPLE people asking you for the error MESSAGE) Yes i am.... Is it this error message you all want then?: Parse error: parse error in C:\wamp\www\kawaii\statusref.php on line 6 Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 Yes that's the error message we all want to see. I think the error is because you're comparing a number with a string. $status is a string, and 1 is a number. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted September 23, 2010 Share Posted September 23, 2010 <?php include "config.php"; $query = "SELECT status FROM gusers"; $result = mysql_query($query)or trigger_error(mysql_error(), E_USER_ERROR); $status = array(1 => 'Member', 'Donator', 'Admin', 'Super Admin'); while ($row = mysql_fetch_row($result)) : echo $status[$row[0]]; endwhile; ?> FYI, you missed a semicolon: $status = "SELECT status FROM gusers" Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 <?php include "config.php"; include "statusref.php"; if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT username, email, name, age, sex, status FROM gusers WHERE id = $id LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "Character: " . $row['username'] . "\n<br>"; echo "Email: " . $row['email'] . "\n<br>"; echo "Real Name: " . $row['name'] . "\n<br>"; echo "Age: " . $row['age'] . "\n<br>"; echo "Sex: " . $row['sex'] . "\n<br>"; echo "Rank: " . $row['status'] . "\n<br>"; } } } here we have my profile page.. It works just fine so don't think too much about that part right now. Now to the actual problem <?php include "config.php"; $query = "SELECT status FROM gusers"; $result = mysql_query($query)or trigger_error(mysql_error(), E_USER_ERROR); $status = array(1 => 'Member', 'Donator', 'Admin', 'Super Admin'); while ($row = mysql_fetch_row($result)) : echo $status[$row[0]]; endwhile; ?> <?php include "config.php"; $status = "SELECT status FROM gusers"; if ($status == 0) { echo "Member"; } elseif ($status == 1) { echo "Admin"; } elseif ($status == 2) { echo "Super Admin"; } ?> Now these codes are supposed to make the status (RANK) appear as text instead the actual number. The code were put into statusref.php which i later included to the profile page, now the text appears... The only problem is, it dosen't get the rank from the profile page that i am on, and it dosen't appear in the right spot where it were supposed to The first code makes this appear: Notice: Undefined index: 0 in C:\wamp\www\kawaii\statusref.php on line 9 Notice: Undefined index: 0 in C:\wamp\www\kawaii\statusref.php on line 9 Notice: Undefined index: 0 in C:\wamp\www\kawaii\statusref.php on line 9 Super AdminCharacter: test Email: test@test.com Real Name: Simon Age: 18 Sex: 1 Rank: 4 You get Super Admin nomatter what profile you go to, and the superadmin stands in same line as Character ... it were supposed to replace the 4 in Rank: This is what happens with the other script: MemberCharacter: test Email: test@test.com Real Name: Simon Age: 18 Sex: 1 Rank: 4 That appears as member, again same problem with position and loading from the actual profile... HELP WOULD BE SOO APPRICIATED Quote Link to comment Share on other sites More sharing options...
Andy-H Posted September 23, 2010 Share Posted September 23, 2010 <?php include "config.php"; //<--add the below line to config.php $statusArray = array(1 => 'Member', 'Donator', 'Admin', 'Super Admin'); //forget statusref// include "statusref.php"; if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT username, email, name, age, sex, status FROM gusers WHERE id = $id LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "Character: " . $row['username'] . "\n<br>"; echo "Email: " . $row['email'] . "\n<br>"; echo "Real Name: " . $row['name'] . "\n<br>"; echo "Age: " . $row['age'] . "\n<br>"; echo "Sex: " . $row['sex'] . "\n<br>"; echo "Rank: " . $statusArray[$row['status']] . "\n<br>"; } } } Whenever you pull status from the users table, to display it as text, use the row pulled as the key in $statusArray. Quote Link to comment Share on other sites More sharing options...
kickstart Posted September 23, 2010 Share Posted September 23, 2010 Hi Think you are getting confused with the 2 scripts (or I am) Try like this include "config.php"; include "statusref.php"; $status = array(1 => 'Member', 'Donator', 'Admin', 'Super Admin'); if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT username, email, name, age, sex, status FROM gusers WHERE id = $id LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "Character: " . $row['username'] . "\n<br>"; echo "Email: " . $row['email'] . "\n<br>"; echo "Real Name: " . $row['name'] . "\n<br>"; echo "Age: " . $row['age'] . "\n<br>"; echo "Sex: " . $row['sex'] . "\n<br>"; echo "Rank: " . $status [$row['status']] . "\n<br>"; } } } All the best Keith Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 Thank you alot! It works like a charm ! Its perfect! 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.