Jump to content

Displaying enum MySQL data on a profile, HELP NEEDED?


jdowen2211

Recommended Posts

I have a social network with user profiles and when a user signs up, they enter whether they are a student, parent or teacher. That is then sent to a MySQL database and is collected successfully. I want that data to display on their profile but in the database it is stored like this: s for student, t for teacher and p for parent. I managed to get it on the profile saying something like this, "username is a s". I want that s to say student and if they are a teacher then I want teacher and so on. Could someone give me some code that will help because everything I have tried so far has failed. Help will be much appreciated.

Link to comment
Share on other sites

<?

$i <-  user status row

switch ($i) {

    case "s":

        echo "student";

        break;

    case "t":

        echo "teacher";

        break;

    case "p":

        echo "parents";

        break;

}

?>

Try gogle it ' php switch'...

Link to comment
Share on other sites

I tried this before and it just said James is a s but I want the s to be Student:

 

if ($person_type == "") {

    $person_type = "";

        } else {

        $person_type = '<br /><br /><strong>' . $username . ' is a ' . $person_type . '';

        }

Link to comment
Share on other sites

It's not working, it's just throwing errors at me. Do I need to put it in the part of the profile where I want it to display or do I put it with the other PHP code at the top of the file that renders the page then echo it out with <?php echo $person_type; ?>

Link to comment
Share on other sites

Well this is the code I'm using and I'm trying to echo it out with <?php echo $person_type; ?> but instead at the top of the profile where errors display it just says 'student' which is a start and when I want it to display in the profile is says 's' still. Once I get it to where I want I'm going to add ' . $username . " is a student/teacher/parent. For now I'm going to put the code below onto the profile where I want it to display.

 

if ($person_type == "") {

    $person_type = "";

} switch ($person_type) {

    case "s":

        echo "student";

        break;

    case "t":

        echo "teacher";

        break;

    case "p":

        echo "parents";

        break;

        }

Link to comment
Share on other sites

I just went to the profile, which in my case is profile.php, and added the following code where I want it to display on the page:

 

<?php if ($person_type == "") {

    $person_type = "";

} switch ($person_type) {

    case "s":

        echo "$username is a Student";

        break;

    case "t":

        echo "$username is a Teacher";

        break;

    case "p":

        echo "$username is a Parent";

        break;

        }

?>

Link to comment
Share on other sites

Here's a way to do it with less code, if you're interested.

 

$types = array('s' => 'Student', 't' => 'Teacher', 'p' => 'Parent');

if( !empty($person_type) ) {
     echo "$username is a {$types[$person_type]}.";
} else {
     echo "$username has not had a person type assigned." // you can drop the else{} clause if not needed . . .
}

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.