Jump to content

[SOLVED] PROBLEM: Notice: Undefined index:.... What is this?


Chezshire

Recommended Posts

I'm trying to build a simple tool which will display the each team/squad and the members assigned to said team/squad. On the advice of a PHPFREAKer, I added the following line of code to the beginning of file <ini_set('error_reporting',E_ALL);>

This line of code produced the following error 32 times, which i believe was once for each person i wanted to list <Notice: Undefined index: TRAINING SQUADRONS in /home/content/z/a/n/zanland/html/xpg/institute/institute2.php on line 167> Now i thought i had defined the index, but i guess not so any help would be appreciated.

 

Thank you!

 

 

This is line sited as the error:

$tempSquad = explode("^", $squadders["TRAINING SQUADRONS"]);

 

 

Full code:

ini_set('error_reporting',E_ALL);

// SQUADRONS

$sql = "SELECT id, squadronDB FROM cerebra WHERE approved=\"true\" AND squadronDB IS NOT NULL AND squadronDB != \"\" AND type=\"student\" AND player > 0";
$result = mysql_query($sql);

$squad = array("ALPHA - Alpha Flight (Advisor)",
"ALPHA - Alpha Flight (Field Leader)", "ALPHA - Alpha Flight (Deputy Leader)",
"ALPHA - Alpha Flight", "BETA - Buckaroo Banzias (Advisor)", "BETA - Buckaroo Banzias (Field Leader)", "BETA - Buckaroo Banzias (Deputy Leader)", "BETA - Buckaroo Banzias", "KAPPA - Corsairs (Advisor)", "KAPPA - Corsairs (Field Leader)", "KAPPA - Corsairs (Deputy Leader)", "KAPPA - Corsairs", "DELTA - Paragons (Advisor)", "DELTA - Paragons (Field Leader)", "DELTA - Paragons (Deputy Leader)", "DELTA - Paragons", "EPSILON - Excaliber (Advisor)", "EPSILON - Excaliber (Field Leader)", "EPSILON - Excaliber (Deputy Leader)", "EPSILON - Excaliber", "OMEGA - Omega Gang (Advisor)", "OMEGA - Omega Gang (Field Leader)", "OMEGA - Omega Gang (Deputy Leader)", "OMEGA - Omega Gang",);

$squadders = array();

WHILE ($squadder = mysql_fetch_assoc($result)) {
$tempSquad = explode("^", $squadders["TRAINING SQUADRONS"]);

foreach ($tempSquad as $thisSquad) {

$key = array_search($thisSquad, $squad);

if ($key) {
if (!isset($squadders[$key])) { $squadders[$key] = array(); }
array_push($squadders[$key], $squadder["id"]);
} // end if in club list

} // end foreach

} // end WHILE

$col = 0;

echo "<br>\n<h2><font color='#A5B9D5'>TRAINING SQUADRONS</font></h2>\n";

echo "<hr color='#050F1D' size='5'>\n";

echo "<table cellpadding='0'><tr>";
for ($i =0; $i < count($squad); $i++) {

if (isset($squadders[$i])) {
if ($col == 0) { echo "<td valign='top'>"; }
echo "<p><b>$squad[$i]</b><br>\n";
foreach ($squadders[$i] as $thisSquadder) {
$safeName = preg_replace("/\"/", """, getSquad($thisSquadder));
$realName = getRealName($thisSquadder);
if ($realName == "(Unrevealed)") { $realName = $safeName; }
echo "<span class='fineprint'><a href=\"/cerebra/display.php?id=$thisSquadder\" title=\"$safeName\">$realName</a></span><br>\n"; }
echo "</p>\n";
$col++;
if ($col == 4) { echo "</td><td width='25'></td>\n"; $col=0; }
} // end if any students in this club

} // end for

IF ($col < 4) { echo "</td>"; }

echo "</tr></table>\n";

 

dont you have to retrieve the value TRAINING SQUADRONS from the database before you can use it? AS far as I can see you are only retrieving 2 fields  (id, squadronDB) from it. Maybe put an * to return all fields until you learn exactly what you will be using?

dont you have to retrieve the value TRAINING SQUADRONS from the database before you can use it? AS far as I can see you are only retrieving 2 fields  (id, squadronDB) from it. Maybe put an * to return all fields until you learn exactly what you will be using?

 

Ewhhh... What does the asterix '*' do? Where would i place the asterix?

 

Thank you!

Thankyou - Sadly i am still confused. I 'm really new to all of this, and tend to do better from seeing examples that being told 'do x' as I'm still unsure what I'm doing. I've added in all the fields i think i need to get the result i'm trying to get which is as follows:

 

Squadron Name

Squadron member (sorted by their code name)

 

Squadron Name is determined by the 'squadronDB' and I've added Codename into the $SQL call as you can see below. I'm still getting the error - 32 of them, one for each student i try to call/print i think. the Error is site as being on line 167,so i'm still not siting the field correctly. I did think that perhaps the problem was a typo -- i spelt the $ squadders and squadder in different places. Now i've corrected that but i still have the error.

 

Help?

 

$tempSquad = explode("^", $squadders["TRAINING SQUADRONS"]);

 

 

ini_set('error_reporting',E_ALL);

// SQUADRONS

$sql = "SELECT id, name, codename, squadronDB FROM cerebra WHERE approved=\"true\" AND squadronDB IS NOT NULL AND squadronDB != \"\" AND type=\"student\" AND player > 0";
$result = mysql_query($sql);

$squad = array("ALPHA - Alpha Flight (Advisor)",
"ALPHA - Alpha Flight (Field Leader)", "ALPHA - Alpha Flight (Deputy Leader)",
"ALPHA - Alpha Flight", "BETA - Buckaroo Banzias (Advisor)", "BETA - Buckaroo Banzias (Field Leader)", "BETA - Buckaroo Banzias (Deputy Leader)", "BETA - Buckaroo Banzias", "KAPPA - Corsairs (Advisor)", "KAPPA - Corsairs (Field Leader)", "KAPPA - Corsairs (Deputy Leader)", "KAPPA - Corsairs", "DELTA - Paragons (Advisor)", "DELTA - Paragons (Field Leader)", "DELTA - Paragons (Deputy Leader)", "DELTA - Paragons", "EPSILON - Excaliber (Advisor)", "EPSILON - Excaliber (Field Leader)", "EPSILON - Excaliber (Deputy Leader)", "EPSILON - Excaliber", "OMEGA - Omega Gang (Advisor)", "OMEGA - Omega Gang (Field Leader)", "OMEGA - Omega Gang (Deputy Leader)", "OMEGA - Omega Gang");

$squadders = array();

WHILE ($squadders = mysql_fetch_assoc($result)) {
$tempSquad = explode("^", $squadders["TRAINING SQUADRONS"]);

foreach ($tempSquad as $thisSquad) {

$key = array_search($thisSquad, $squad);

if ($key) {
if (!isset($squadders[$key])) { $squadders[$key] = array(); }
array_push($squadders[$key], $squadders["id"]);
} // end if in squad list

} // end foreach

} // end WHILE

$col = 0;

echo "<br>\n<h2><font color='#A5B9D5'>TRAINING SQUADRONS</font></h2>\n";

echo "<hr color='#050F1D' size='5'>\n";

echo "<table cellpadding='0'><tr>";
for ($i =0; $i < count($squad); $i++) {

if (isset($squadders[$i])) {
if ($col == 0) { echo "<td valign='top'>"; }
echo "<p><b>$squad[$i]</b><br>\n";
foreach ($squadders[$i] as $thisSquadders) {
$safeName = preg_replace("/\"/", """, getSquad($thisSquadders));
$realName = getRealName($thisSquadders);
if ($realName == "(Unrevealed)") { $realName = $safeName; }
echo "<span class='fineprint'><a href=\"/cerebra/display.php?id=$thisSquadders\" title=\"$safeName\">$realName</a></span><br>\n"; }
echo "</p>\n";
$col++;
if ($col == 4) { echo "</td><td width='25'></td>\n"; $col=0; }
} // end if any students in this club

} // end for

IF ($col < 4) { echo "</td>"; }

echo "</tr></table>\n";



?>

 

 

I am wondering where you are getting TRAINING SQUADRONS form?

 

when your pulling the array form the result row the array will be keyed with the selected fields value, i'm not sure but i think you need to make sure that it's not [- TRAINING_SQUADRONS -] if that's not the case then try to add that field to your query.

I am wondering where you are getting TRAINING SQUADRONS form?

 

when your pulling the array form the result row the array will be keyed with the selected fields value, i'm not sure but i think you need to make sure that it's not [- TRAINING_SQUADRONS -] if that's not the case then try to add that field to your query.

 

Hi ron8000 and everyone else who's looked at this so far. Thanks! I changed the line with the reported error from:

$tempSquad = explode("^", $squadders["TRAINING SQUADS"]);

to

$tempSquad = explode("^", $squadders["squadronDB"]);

 

I thought that that line was listing the category name for display on the page, not calling the value so to speak. So the error message went away YEAH! Sadly though nothing is displaying. But at least i've gotten through my second hurdle thanks to you Ron and all the other wonderful helpful folks here at PHPFREAKS!

 

So i will list this problem as solved. Thank you very much

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.