Jump to content

[SOLVED] SIMPLE QUESTION: Hide selection from displaying when 'none' is selected.


Chezshire

Recommended Posts

I'm trying to evolve my character creation form so as to eliminate what I consider to be a 'bug'. I have several 'pull-down' menu's so that players can select a character trait and it will appear with the formating that I want it to appear with so that the site will be very uniform in appearance (www.xpg.us - it's a silly home brewed x-men based sim i've been working on to teach myself how to do html) Currently, if someone selects 'none' for a 'mentor', 'tutor', or other such option, the character sheets/bio's will display the selection as: Tutor: Tutor, or Mentor: Mentor and this looks DUMB: DUMB to me. And I've been trying for two nights to solve it exploring various 'die' options and 'display.hide' options etc. And i'm getting now where fast so I thought i'd beg to the PHP gods for guidance and help.

 

Hello God(s)

 

URL SAMPLE: http://www.xpg.us/cerebra/display.php?id=962

If you check this url you will see mid-way down that the Character "Wing" from Astonishing X-Men's "Student Mentor" is Mentor and his "Assigned Tutor" is "Tutor" I would like it if when people select 'none' form the pull down option, that this would not display at all. I.E. if they have no Mentor, we don't need to see that they have no mentor, or at least it should display as "Mentor: None", not ""Student Mentor: Mentor"

 

This is my Code for the Mentor portion:


if ($mentorName != "Storyteller") {
if ($mentorName != "display: none"> {
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Student Mentor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$mentor' title='Get info on character: $mentorName'>$mentorName</a></p></td></tr>\n"; }

 

The last thing iv'e tried to affect the result I wanted was in the second row with an 'if' statement which just broke the whole page.

Any help as always is richly appreciated by me and my silly roleplaying friends!

 

Thank you everyone!

-Chez

Link to comment
Share on other sites

Are you using PHP4 or 5?

 

How are you getting the mentor name?

 

if ($mentorName == '')
{
   print '' // or print 'Unselected' etc etc
}
else
{
   print "<a href='display.php?id=$mentor' title='Get info on character: $mentorName'>$mentorName</a>"
}

 

Link to comment
Share on other sites

I believe I'm using working in four, but I will confirm this with my friend who helped to get me started. Then mentor name is gathered from the database and assigned by a moderator.

 

this is the full code for that portion of the page:

<?php
if ($gradeLevels) {echo "<tr><td align=\"right\" valign=\"top\"><p><b>Education/Degree:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $gradeLevels[$educationDB] . "</p></td></tr>\n"; }

if ($room) { echo "<tr><td align=\"right\" valign=\"top\"><p><b>Room Assignment:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>";
$roomNumber = preg_replace("/^(GD|BD)(\d\d\d).+/i","$1$2",$room);
$roomExtra = preg_replace("/^(GD|BD)(\d\d\d)/i","",$room);
if (preg_match("/^GD/",$roomNumber)) { echo "<a href=\"javascript:openimage('/institute/floorplan.php?floor=2&dorm=girls',800,625,true)\" title=\"Click for an interactive floor plan of the mansion\" onmouseover=\"window.status='Click for an interactive floor plan of the mansion'\">$roomNumber</a>";
} else {
echo "<a href=\"javascript:openimage('/institute/floorplan.php?floor=2&dorm=boys',800,625,true)\" title=\"Click for an interactive floor plan of the mansion\" onmouseover=\"window.status='Click for an interactive floor plan of the mansion'\">$roomNumber</a>";
} // end if boys
if ($roomExtra) {
echo linkChars($roomExtra);
} // end if extra text
echo "</p></td></tr>\n"; } // end if room

if ($schoolclubs) { echo "<tr><td align=\"right\" valign=\"top\"><p><b>School Clubs:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . implode(", ", explode("^",$schoolclubs)) . "</p></td></tr>\n"; } // end if clubs

if ($squadronNames) {echo "<tr><td align=\"right\" valign=\"top\"><p><b>Training Squadron:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $squadronNames[$squadronDB] . "</p></td></tr>\n"; }

if ($advisor) {
echo "<!-- Advisor: $advisor -->\n";
$advisorName = getChar($advisor);
if ($advisorName != "Storyteller") {
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Faculty Advisor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$advisor' title='Get info on character: $advisorName'>$advisorName</a></p></td></tr>\n"; }

if ($mentorName != "Storyteller") {
if ($mentorName != "display: none"> {
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Student Mentor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$mentor' title='Get info on character: $mentorName'>$mentorName</a></p></td></tr>\n"; }

if ($tutorName != "Storyteller") {
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Assigned Tutor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$tutor' title='Get info on character: $tutorName'>$tutorName</a></p></td></tr>\n"; }
} // end if advisor
$testy = mysql_query("SELECT id,codename from cerebra WHERE advisor = $id AND approved=\"true\" AND type=\"student\" AND player > 0");
if (mysql_num_rows($testy)) {
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Advisor for:</b></p></td>\n";
$studentArray = array();
WHILE ($advisee = mysql_fetch_assoc($testy)) {
array_push($studentArray, "<a href='display.php?id=" . $advisee["id"] . "' title='Get info on character: " . $advisee["codename"] . "'>" . $advisee["codename"] . "</a>");
} // end WHILE
$studentString = implode(", ", $studentArray);
echo "<td width=\"10\"> </td><td valign=\"top\"><p>$studentString</p></td></tr>\n";
} // end if advisor to students
echo "</table>";
} // end if a resident at the institute
?>

 

 

Thank you for looking

Chez

P.S. Ironman is awesome!

 

Link to comment
Share on other sites

Hi,

  I tried implementing the suggested fix and received the following error message:

Parse error: parse error, unexpected T_STRING in ...xpg/cerebra/displayTest.php on line 182

 

Line 182:    print '' // or print 'Unselected' etc etc

 

The 'parse error, unexpected T_String' error is the bane of my existence. Help please

 

 

Link to comment
Share on other sites

Hi,

  I tried implementing the suggested fix and received the following error message:

Parse error: parse error, unexpected T_STRING in ...xpg/cerebra/displayTest.php on line 182

 

Line 182:    print '' // or print 'Unselected' etc etc

 

The 'parse error, unexpected T_String' error is the bane of my existence. Help please

 

 

 

in an if else statement, you have to include a line terminator....  ;

 

so

 

if (statement) {

      print '';

} else {

      print 'other stuff';

}

 

I am sure it was just a typo :)

Link to comment
Share on other sites

Thanks once again for the kindly assist, unfortunately I'm still getting the T_String error.

 

This is currently where I landed with the code

if ($mentorName != "Storyteller") {
if ($mentorName !== '') 
{
   print ""; 
}
else
{
   print "<a href='display.php?id=$mentor' title='Get info on character: $mentorName'>$mentorName</a>";
}
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Student Mentor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$mentor' title='Get info on character: $mentorName'>$mentorName</a></p></td></tr>\n"; }

 

 

I'm really unfamiliar with the whole 'print' function, also I'm not sure if folks are short handing their comments or if i'm suppose to be implimenting the 'etc. etc.' statements. I'm very new to all of this.

 

Thanks for any help offered, if nothing else it's very educational and i appreciate that very very much!

-Chez

Link to comment
Share on other sites

Hello again,

  I'm continuing to be baffled by my current issue which is to get the option and selected value to not display if ' -- None -- ' is selected. To that end I tried going a completely new direction and managed to get a completely different error (it happens further down line wise so i think i'm making progress?) Still, it's not working so if you would take a look at this attempt and offer advice to a novice it would be much appreciated and I promise to burn a Intel Chip tonight in your name ;)

if ($mentor) {
echo "<!-- Mentor: $mentor -->\n";
$mentorName = getChar($mentor);
if ($mentorName != "Storyteller") {
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Student Mentor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$mentor' title='Get info on Student Mentor: $mentorName'>$mentorName</a></p></td></tr>\n"; }

 

As always any help is muchly apprecaited. Thanks as always for any considerations or suggestions

 

Link to comment
Share on other sites

Hello,

  I'm still trying to find a solution to the bug I'm experiencing. I've tried a few things but nothing has worked -- It may be that i'm not understanding the advice that has been offered as I am a novice.

  Looking forwards with crossed fingers to an answer

    thanks

Link to comment
Share on other sites

Hi

 

I figured out the issue and was able to resolve it

 

yeah for me, yeah for me (said in the voice of 'Mayor Bee' from Family Guy)

 

Below is the code, which I'm not sure why it works but it does. Thank you to those who offered suggestions and pointers as it help to get me thinking in different directions which I very much appreciate!

 

if ($gradeLevels) 
{
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Education/Degree:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $gradeLevels[$educationDB] . "</p></td></tr>\n"; 
}
if ($room) { echo "<tr><td align=\"right\" valign=\"top\"><p><b>Room Assignment:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>";
	$roomNumber = preg_replace("/^(GD|BD)(\d\d\d).+/i","$1$2",$room);
	$roomExtra = preg_replace("/^(GD|BD)(\d\d\d)/i","",$room);
if (preg_match("/^GD/",$roomNumber)) 
{ 
echo "<a href=\"javascript:openimage('/institute/floorplan.php?floor=2&dorm=girls',800,625,true)\" title=\"Click for an interactive floor plan of the mansion\" onmouseover=\"window.status='Click for an interactive floor plan of the mansion'\">$roomNumber</a>";
} else {
echo "<a href=\"javascript:openimage('/institute/floorplan.php?floor=2&dorm=boys',800,625,true)\" title=\"Click for an interactive floor plan of the mansion\" onmouseover=\"window.status='Click for an interactive floor plan of the mansion'\">$roomNumber</a>";
} // end if boys
if ($roomExtra) 
{
echo linkChars($roomExtra);
} // end if extra text
echo "</p></td></tr>\n"; 
} // end if room
if ($schoolclubs) 
{ 
echo "<tr><td align=\"right\" valign=\"top\"><p><b>School Clubs:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . implode(", ", explode("^",$schoolclubs)) . "</p></td></tr>\n"; 
} // end if clubs
if ($squadronNames) 
{
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Training Squadron:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $squadronNames[$squadronDB] . "</p></td></tr>\n"; 
}
if ($advisor) 
{
echo "<!-- Advisor: $advisor -->\n";
$advisorName = getChar($advisor);
if ($advisorName != "Storyteller") 
{
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Faculty Advisor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$advisor' title='Get info on character: $advisorName'>$advisorName</a></p></td></tr>\n"; 
}
echo "<!-- Mentor: $mentor -->\n";
$mentorName = getChar($mentor);
if ($mentorName != "Storyteller") 
{
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Student Mentor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$mentor' title='Get info on Student Mentor: $mentorName'>$mentorName</a></p></td></tr>\n"; 
}
echo "<!-- Tutor: $tutor -->\n";
$tutorName = getChar($tutor);
if ($tutorName != "Storyteller") 
{
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Assigned Tutor:</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p><a href='display.php?id=$tutor' title='Get info on Student Tutor: $tutorName'>$tutorName</a></p></td></tr>\n"; 
}
} // end if advisor
	$testy = mysql_query("SELECT id,codename from cerebra WHERE advisor = $id AND approved=\"true\" AND type=\"student\" AND player > 0");
if (mysql_num_rows($testy)) 
{
echo "<tr><td align=\"right\" valign=\"top\"><p><b>Advisor for:</b></p></td>\n";
	$studentArray = array();
WHILE ($advisee = mysql_fetch_assoc($testy)) 
{
array_push($studentArray, "<a href='display.php?id=" . $advisee["id"] . "' title='Get info on character: " . $advisee["codename"] . "'>" . $advisee["codename"] . "</a>");
} // end WHILE
$studentString = implode(", ", $studentArray);
echo "<td width=\"10\"> </td><td valign=\"top\"><p>$studentString</p></td></tr>\n";
} // end if advisor to students
echo "</table>";
} // end if a resident at the institute
?>

<hr color="#050F1D" size="5">
<?php
if ($goals || $orientation || $personality || $demeanor || $nature) {
echo "<div><h2 class=\"spaceafter\"><font color=\"#A5B9D5\">Psychological Profile</font></h2></div>\n";
?>

<table cellpadding="0" cellspacing="0">
<?php
$theseFields = array("concept","orientation","demeanor","nature","personality","goals");
foreach ($theseFields as $thisField) {
if (${$thisField}) { echo "<tr><td align=\"right\" valign=\"top\"><p><b>" . ${$thisField . "Name"} . ":</b></p></td>\n";
echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . ${$thisField} . "</p></td></tr>\n";
} // end if value
} // end FOREACH
} // end if any psychological fields
?>

 

 

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.