Chezshire Posted September 10, 2008 Share Posted September 10, 2008 Hi, my display code isn't working correctly and I can't figure out what is wrong. The squad value does not display, yet the education name value does. I've checked my database and the database shows that the info is there, so i'm at a loss as to why one does and one doesn't. Help? <?php if ($gradeLevels) { echo "<tr><td align=\"right\" valign=\"top\"><p><b>EDUCATION:</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:</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 CLUB:</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>SQUAD/TEAM:</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 ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted September 10, 2008 Share Posted September 10, 2008 Is that your entire script? Where do the values for variables such as $gradeLevels come from? Quote Link to comment Share on other sites More sharing options...
Chezshire Posted September 10, 2008 Author Share Posted September 10, 2008 Hello btherl, the values are pulled from the functions.php which contains '$squadronNames'. I hope I'm understanding your question as I'm very much a newb and don't know what I'm doing (but I am taking classes this fall/winter finally!) From earlier in code: // "modelname","song","song_link" //"Model", "Song", "Song Link", $fields = array("codename", "name", "identitystatus", "ocfcDB", "formeraliases", "nickname", "height1", "height2", "weight1", "weight2", "weight3", "hair", "eyes", "ethnicity", "dateofbirth", "age", "educationDB", "gender", "orientation", "characteristics", "baseofoperations", "affiliation", "formeraffiliation", "type", "concept", "occupation", "formeroccupation", "legalstatus", "maritalstatus", "citizenship", "placeofbirth", "appearance", "quote", "modelname", "waiver", "song", "song_link", "squadronDB", "fightingDB", "agilityDB", "enduranceDB", "strengthDB", "reasonDB", "intuitionDB", "psycheDB", "classificationsDB", "advantagesDB", "powersDB", "powersource", "skilllevel", "wealthDB", "skills", "fightingskills", "resources", "tech", "relatives", "contacts", "enemies", "uniformDB", "equipment", "transportation", "demeanor", "nature", "personality", "wealthDB", "goals", "history", "room", "advisor", "mentor", "tutor", "schoolclubs", "powerrankDB"); $fieldNames = array("CODENAME", "NAME", "IDENTITY STATUS","CHARACTER TYPE", "FORMER ALIASES", "NICKNAME", "HEIGHT1", "HEIGHT2", "WEIGHT1", "WEIGHT2", "WEIGHT3", "HAIR", "EYES", "ETHNICITY", "BIRTHDATE", "AGE", "EDUCATION", "GENDER", "ORIENTATION", "CHARACTERISTICS", "BASE OF OPERATIONS", "AFFILIATION", "FORMER AFFILIATION", "TYPE", "CHARACTER CONCEPT", "OCCUPATION", "FORMER OCCUPATION", "LEGAL STATUS", "MARITAL STATUS", "CITIZENSHIP", "PLACE OF BIRTH", "APPEARANCE", "QUOTE", "MODEL", "WAIVER", "SONG", "SONG LINK", "SQUADRONDB", "FIGHTING", "AGILITY", "ENDURANCE", "STRENGTH", "REASON", "INTUITION", "PSYCHE", "CLASSIFICATIONS", "ADVANTAGES", "POWERS", "POWER SOURCE","SKILLS", "RESOURCES", "DISADVANTAGES", "SKILLS", "RESOURCES", "TECH", "RELATIVES", "CONTACTS", "ENEMIES", "UNIFORM", "EQUIPMENT", "TRANSPORTATION", "DEMEANOR", "NATURE", "PERSONALITY", "WEALTH", "GOALS", "HISTORY", "ROOM", "ADVISOR", "MENTOR", "TUTOR", "SCHOOL CLUBS","POWER RANK"); from functions.php: $squadronNames = array( "None", "Alpha Flight", "Buckaroo Banzias", "Corsairs", "Excaliber", "Omega Gang", "Paragons", "X-MEN (Blue)", "X-MEN (Gold)", "Reservist", "Unnassigned"); Quote Link to comment Share on other sites More sharing options...
btherl Posted September 10, 2008 Share Posted September 10, 2008 Thanks, that partially answers my question. To fetch data from a database you must call mysql_query(), followed by mysql_fetch_row() or a similar function. But I don't see any mysql functions before your use of $squadronNames[$squadronDB]. Can you show me where $squadronDB comes from? Also can you clarify exactly which line is not displaying correctly? (If there are many lines not working, just pinpoint one of them exactly). Quote Link to comment Share on other sites More sharing options...
Chezshire Posted September 10, 2008 Author Share Posted September 10, 2008 Thanks for the reply btherl, mysql_queries lately have been the bane of my existence it seems, maybe solving this will lead me to how i can resolve my other problem too . I think this is my sql call? $characterSQL = "SELECT *, IFNULL(FLOOR((TO_DAYS('$gameDate') + FLOOR((TO_DAYS(NOW()) - TO_DAYS('$realDate')) / 14) - TO_DAYS(dateofbirth)) / 365.25) ,0) AS age, DATE_FORMAT(dateofbirth, '%b %e, %Y') AS dateofbirth FROM cerebra where id=$id"; echo "<!-- SQL: $characterSQL -->\n"; $result=mysql_query($characterSQL, $db); if (!mysql_num_rows($result)) { errorpage("There is no Cerebra record with that id number. Please check the link you used to access this page and try again, or check the <a href='/cerebra.php'>Cerebra main page</a> for the record you're looking for."); die; } $record = mysql_fetch_assoc($result); echo "<!-- ID: $id -->\n"; } else { header("location: /cerebra.php"); die; } // end if ID The only thing which is not working in the whole page is this piece: squadrons if ($squadronNames) { echo "<tr><td align=\"right\" valign=\"top\"><p><b>SQUAD/TEAM:</b></p></td>\n"; echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $squadronNames[$squadronDB] . "</p></td></tr>\n"; } I look forwards to any wisdom you might have to share! Quote Link to comment Share on other sites More sharing options...
btherl Posted September 10, 2008 Share Posted September 10, 2008 Thanks .. hmm. So far I see nothing that sets $squadronDB. Can you look through your code to see where it is set? It may look something like this: $squadronDB = $record['squadron']; At least that's what I would expect. Quote Link to comment Share on other sites More sharing options...
Chezshire Posted September 10, 2008 Author Share Posted September 10, 2008 Hmmms.... Line 4+5 say: $id=""; $record=array(); Line#24 says: $record = mysql_fetch_assoc($result); echo "<!-- ID: $id -->\n"; } else { header("location: /cerebra.php"); die; } // end if ID Line #39 says: $patterns = array ("/\"/","/[\n\r\f]+/"); $replace = array (""","</p>\n<p>"); FOR ($i=0; $i < count($fields); $i++) { ${$fields[$i]} = preg_replace($patterns, $replace, trim($record[$fields[$i]])); ${$fields[$i] . "Name"} = $fieldNames[$i]; } // end FOREACH Does any of that do like an over all record statement? I don't see a record set up to pull education either, yet education works be the squad doesn't. Quote Link to comment Share on other sites More sharing options...
btherl Posted September 11, 2008 Share Posted September 11, 2008 Yes that does look right. So it takes "squadronDB" from the $fields array and then sets a variable $squadronDB from the value $record['squadronDB'] Earlier you said that squadronDB is set correctly in the database. The first thing I would do is add this code just after $record is set: print "<pre>"; var_dump($record); print "</pre>"; die(); What this will do is dump the contents of $record and immediately terminate the script. Take a look in the output and see if 'squadronDB' is set correctly. If it IS set correctly, then the bug comes later. If it is NOT set correctly, then the bug is probably in your db query. There is something I want to clarify: $squadronNames = array( "None", "Alpha Flight", "Buckaroo Banzias", "Corsairs", "Excaliber", "Omega Gang", "Paragons", "X-MEN (Blue)", "X-MEN (Gold)", "Reservist", "Unnassigned"); echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $squadronNames[$squadronDB] . "</p></td></tr>\n"; This implies that $squadronDB is expected to be a number ranging from 0 to 1 less than the number of squadron names in that list. Does that sound right? Quote Link to comment Share on other sites More sharing options...
Chezshire Posted September 12, 2008 Author Share Posted September 12, 2008 Thanks for the help, So this code worked: if ($squadronDB) { echo "<!-- SquadronDB: $squadronDB -->\n"; echo "<tr><td align=\"right\" valign=\"top\"><p><b>SQUAD/TEAM:</b></p></td>\n"; echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $squadronDB . "</p></td></tr>\n"; } I dropped the if statement, and then changed ' " . $squadronNames[$squadronDB] . "</p></td></tr>\n"; ' to ' " . $squadronDB . "' and it works! Thanks for the help! Quote Link to comment 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.