Xtremer360 Posted May 9, 2010 Share Posted May 9, 2010 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/ Share on other sites More sharing options...
sKunKbad Posted May 9, 2010 Share Posted May 9, 2010 if(isset($var)) { echo $var; // now you won't get the warning message, because you checked that it was set. } Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1055556 Share on other sites More sharing options...
Xtremer360 Posted May 9, 2010 Author Share Posted May 9, 2010 Where do I place that or does it matter? Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1055559 Share on other sites More sharing options...
sKunKbad Posted May 9, 2010 Share Posted May 9, 2010 for instance: if (isset($champion) && strlen ($champion) < 1) { //line 45 or if (isset($con1) && strlen ($con1) < 1) { //line 54 Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1055564 Share on other sites More sharing options...
Xtremer360 Posted May 10, 2010 Author Share Posted May 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1055632 Share on other sites More sharing options...
Xtremer360 Posted May 10, 2010 Author Share Posted May 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056073 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2010 Share Posted May 10, 2010 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.) Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056080 Share on other sites More sharing options...
Xtremer360 Posted May 10, 2010 Author Share Posted May 10, 2010 What should I do? Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056089 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2010 Share Posted May 10, 2010 What value do you want the variables to have when there is a NULL? Just add an else{} clause to the if(isset()){} statement and assign the value you want or you can probably just remove the if(isset()){} test. Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056092 Share on other sites More sharing options...
Xtremer360 Posted May 10, 2010 Author Share Posted May 10, 2010 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056096 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2010 Share Posted May 10, 2010 I removed the isset No, you didn't - if (isset($row[$fieldlabel])) Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056097 Share on other sites More sharing options...
Xtremer360 Posted May 10, 2010 Author Share Posted May 10, 2010 http://kansasoutlawwrestling.com/champions Ding ding ding we have a winner. Quote Link to comment https://forums.phpfreaks.com/topic/201199-undefined-variables/#findComment-1056100 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.