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. 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. 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'... 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 . ''; } 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 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; ?> 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 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; } 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. 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 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? 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; } ?> 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 . . . } 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? 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. 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! 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
Archived
This topic is now archived and is closed to further replies.