jdowen2211 Posted July 30, 2011 Share Posted July 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/ Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2011 Share Posted July 30, 2011 Post what you've tried. Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249426 Share on other sites More sharing options...
voip03 Posted July 30, 2011 Share Posted July 30, 2011 <? $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'... Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249427 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 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 . ''; Â Â Â Â } Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249429 Share on other sites More sharing options...
voip03 Posted July 30, 2011 Share Posted July 30, 2011 please mark as solved. the topic solved button can be found at the bottom left of the page Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249434 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249438 Share on other sites More sharing options...
voip03 Posted July 30, 2011 Share Posted July 30, 2011 what kind of output u need  Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249439 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 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; Â Â Â Â } Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249441 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 Thanks for your help, I've done it now. Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249447 Share on other sites More sharing options...
voip03 Posted July 30, 2011 Share Posted July 30, 2011 $person_type = contain what Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249448 Share on other sites More sharing options...
voip03 Posted July 30, 2011 Share Posted July 30, 2011 how do u do it? Â Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249449 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 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; Â Â Â Â } ?> Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249486 Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2011 Share Posted July 30, 2011 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 . . . } Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249494 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 Is the way I've done it ok though? Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249497 Share on other sites More sharing options...
Pikachu2000 Posted July 30, 2011 Share Posted July 30, 2011 Yeah, it should work just fine. I was just tossing out the idea, and showing you another way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249498 Share on other sites More sharing options...
jdowen2211 Posted July 30, 2011 Author Share Posted July 30, 2011 Oh ok that's cool, thanks for the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/243287-displaying-enum-mysql-data-on-a-profile-help-needed/#findComment-1249519 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.