Jump to content

Transforming a number to text


snallemap

Recommended Posts

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

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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"

Link to comment
Share on other sites

<?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 :(

Link to comment
Share on other sites

 

<?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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.