Jump to content

Recommended Posts

<?php
print "<div id='champions'>\n";

    print "<h1 class=backstage>KOW Champions</h1>\n";
print "<table cellspacing='0px' cellpadding='5px' style='border: 0px;'><tr>";

$query = "SELECT title.name AS title, title.shortname AS shortname, title.champ_id AS championid, title.con1_id AS con1id, title.con2_id AS con2id, title.con3_id AS con3id, title.con4_id AS con4id, title.con5_id AS con5id, biochamp.posername AS posername, biochamp.username AS championusername, biochamp.charactername AS champion, biocon1.username AS con1username, biocon1.charactername AS con1, biocon2.username AS con2username, biocon2.charactername AS con2, biocon3.username AS con3username, biocon3.charactername AS con3, biocon4.username AS con4username, biocon4.charactername AS con4, biocon5.username AS con5username, biocon5.charactername AS con5 FROM `efed_list_titles` AS title LEFT JOIN `efed_bio` AS biochamp ON title.champ_id = biochamp.id LEFT JOIN `efed_bio` AS biocon1 ON title.con1_id = biocon1.id LEFT JOIN `efed_bio` AS biocon2 ON title.con2_id = biocon2.id LEFT JOIN `efed_bio` AS biocon3 ON title.con3_id = biocon3.id LEFT JOIN `efed_bio` AS biocon4 ON title.con4_id = biocon4.id LEFT JOIN `efed_bio` AS biocon5 ON title.con5_id = biocon5.id WHERE title.status_id = '1' ORDER BY title.sortorder"; 

    if(!$result = mysql_query ($query)){ debug($query);  }

    while ($row = mysql_fetch_assoc($result))

    {

$fieldarray=array('title','shortname','championid','championusername','champion','con1id','con1','con1username','con2id','con2','con2username','con3id','con3','con3username','con4id','con4','con4username','con5id','con5','con5username','posername');

        foreach ($fieldarray as $fieldlabel)

        {

            if (isset($row[$fieldlabel])) 

            { 

                $$fieldlabel=$row[$fieldlabel];

                $$fieldlabel=cleanquerydata($$fieldlabel);

            }

        }



        print "<td><span class='large'>".$title."</span>\n";

        if (file_exists($dirpath.'/images/titles/'.$shortname.'.jpg'))
        {
            print "<img style='width: 240px; height: 75px;' class='champion' src='/backstage/images/titles/".$shortname.".jpg'></img>\n";
        }
        else{
            print "<img style='width: 240px; height: 75px;' class='champion' src='/backstage/images/titles/default.jpg'></img>\n";
        }
        
        if (strlen ($champion) < 1) {
            print "<span class='medium'>Vacant</span><br>";
            }
        else {
        print "<span class='medium'><a href='bio.php?username=".$championusername."'>".$champion."</a></span><br>\n";
        }

        print "<span class='contender'>Contenders</span><ul>\n";
        
        if (strlen ($con1) < 1) {
            print "<li><span class='medium'>TBD</span></li><br>";
            }
        else {
        print "<li><a href='backstage/bio.php?username=".$con1username."'>".$con1."</a></li>\n";
        }
        if (strlen ($con2) < 1) {
            print "<li><span class='medium'>TBD</span></li><br>";
            }
        else {
            print "<li><a href='backstage/bio.php?username=".$con2username."'>".$con2."</a></li>\n";
        }
        if (strlen ($con3) < 1) {
            print "<li><span class='medium'>TBD</span></li><br>";
            }
        else {
            print "<li><a href='backstage/bio.php?username=".$con3username."'>".$con3."</a></li>\n";
        }
        if (strlen ($con4) < 1) {
            print "<li><span class='medium'>TBD</span></li><br>";
            }
        else {
            print "<li><a href='backstage/bio.php?username=".$con4username."'>".$con4."</a></li>\n";
        }
        if (strlen ($con5) < 1) {
            print "<li><span class='medium'>TBD</span></li><br>";
            }
        else {
            print "<li><a href='backstage/bio.php?username=".$con5username."'>".$con5."</a></li>\n";
        }
        print "</ul></td>\n";

        unset ($champion);

        unset ($championusername);

        unset ($con1);

        unset ($con1username);

        unset ($con2);

        unset ($con2username);

        unset ($con3);

        unset ($con3username);

        unset ($con4);

        unset ($con4username);

        unset ($con5);

        unset ($con5username);

    }

    print "</tr></table>";
?> 

 

Will this bit of coding it keeps telling me that my champion, con1_id, con2_id, con3_id, con4_id, and con5_id variables are undefined but they are. They just have 0 for their data in my database.  Okay so it dawned on me to go ahead and just put some test values in the database for champ_id,con1_id, and so on and then it showed everything correctly so basically I guess that means that having a 0 value is causing it problems and I don't know why because I have in my code if the variable of champid or whatever is 0 then put Vacant but don't know why.

Link to comment
https://forums.phpfreaks.com/topic/201199-undefined-variables/
Share on other sites

I did try that and it didn't work.

 

Link is here: http://kansasoutlawwrestling.com/champions

 

If you noticed it shows the correct stuff such as the TBD and Vacant but still shows those errors with it.

 

Final product of the page should look like this: http://kansasoutlawwrestling.com/backstage/content.php?p=champions

Link to comment
https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1055632
Share on other sites

Okay so it dawned on me to go ahead and just put some test values in the database for champ_id,con1_id, and so on and then it showed everything correctly so basically I guess that means that having a 0 value is causing it problems and I don't know why because I have in my code if the variable of champid or whatever is 0 then put Vacant but don't know why.

Link to comment
https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056073
Share on other sites

When you do a left join and there are no matching results on the right hand side, NULLs are used for values.

 

You are getting NULL values (test by using var_dump() on each value.)

 

Php does not consider a NULL value to be set and your isset() code is being skipped (just tested.)

Link to comment
https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056080
Share on other sites

I removed the isset and its still doing it.

 

<?php
print "<div id='champions'>\n";

print "<h1 class=backstage>KOW Champions</h1>\n";

print "<table cellspacing='0px' cellpadding='5px' style='border: 0px;'><tr>";



$query = "SELECT title.name AS title, title.shortname AS shortname, title.champ_id AS championid, title.con1_id AS con1id, title.con2_id AS con2id, title.con3_id AS con3id, title.con4_id AS con4id, title.con5_id AS con5id, biochamp.posername AS posername, biochamp.username AS championusername, biochamp.charactername AS champion, biocon1.username AS con1username, biocon1.charactername AS con1, biocon2.username AS con2username, biocon2.charactername AS con2, biocon3.username AS con3username, biocon3.charactername AS con3, biocon4.username AS con4username, biocon4.charactername AS con4, biocon5.username AS con5username, biocon5.charactername AS con5 FROM `efed_list_titles` AS title LEFT JOIN `efed_bio` AS biochamp ON title.champ_id = biochamp.id LEFT JOIN `efed_bio` AS biocon1 ON title.con1_id = biocon1.id LEFT JOIN `efed_bio` AS biocon2 ON title.con2_id = biocon2.id LEFT JOIN `efed_bio` AS biocon3 ON title.con3_id = biocon3.id LEFT JOIN `efed_bio` AS biocon4 ON title.con4_id = biocon4.id LEFT JOIN `efed_bio` AS biocon5 ON title.con5_id = biocon5.id WHERE title.status_id = '1' ORDER BY title.sortorder"; 


if(!$result = mysql_query ($query)){ debug($query);  }

while ($row = mysql_fetch_assoc($result))

{

$fieldarray=array('title','shortname','championid','championusername','champion','con1id','con1','con1username','con2id','con2','con2username','con3id','con3','con3username','con4id','con4','con4username','con5id','con5','con5username','posername');

	foreach ($fieldarray as $fieldlabel)

	{

		if (isset($row[$fieldlabel])) 

		{ 

			$$fieldlabel=$row[$fieldlabel];

			$$fieldlabel=cleanquerydata($$fieldlabel);

		}

	}

print "<td><span class='large'>".$title."</span>";

	if (file_exists('images/titles/'.$shortname.'.jpg'))
	{
		print "<img style='width: 240px; height: 75px;' class='champion' src='images/titles/".$shortname.".jpg'></img>\n";
	}
	else{
		print "<img style='width: 240px; height: 75px;' class='champion' src='images/titles/default.jpg'></img>\n";
	}

	if ( strlen ($champion) < 1) {
    		print "<span class='medium'>Vacant</span><br>";
		}
	else {
    	print "<span class='medium'><a href='bio.php?username=".$championusername."'>".$champion."</a></span><br>\n";
	}

	print "<span class='contender'>Contenders</span><ul>\n";

	if ( strlen ($con1) < 1) {
    		print "<li><span class='medium'>TBD</span></li><br>";
		}
	else {
    	print "<li><a href='backstage/bio.php?username=".$con1username."'>".$con1."</a></li>\n";
	}
	if (strlen ($con2) < 1) {
    		print "<li><span class='medium'>TBD</span></li><br>";
		}
	else {
    		print "<li><a href='backstage/bio.php?username=".$con2username."'>".$con2."</a></li>\n";
	}
	if (strlen ($con3) < 1) {
    		print "<li><span class='medium'>TBD</span></li><br>";
		}
	else {
    		print "<li><a href='backstage/bio.php?username=".$con3username."'>".$con3."</a></li>\n";
	}
	if (strlen ($con4) < 1) {
    		print "<li><span class='medium'>TBD</span></li><br>";
		}
	else {
    		print "<li><a href='backstage/bio.php?username=".$con4username."'>".$con4."</a></li>\n";
	}
	if ( strlen ($con5) < 1) {
    		print "<li><span class='medium'>TBD</span></li><br>";
		}
	else {
    		print "<li><a href='backstage/bio.php?username=".$con5username."'>".$con5."</a></li>\n";
	}
	print "</ul></td>\n";

	unset ($champion);

	unset ($championusername);

	unset ($con1);

	unset ($con1username);

	unset ($con2);

	unset ($con2username);

	unset ($con3);

	unset ($con3username);

	unset ($con4);

	unset ($con4username);

	unset ($con5);

	unset ($con5username);

}

print "</tr></table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056096
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.