Xtremer360 Posted October 6, 2010 Share Posted October 6, 2010 It DOES NOT any of this information for the wrestlers that DO NOT have a manager and if they do then it shows all as undefined variables. I know it has to do with the while statement I'm sure it's how its echoing the info and I don't know how to modify it so that I can echo the variable and if there's no value for the row then it shows N/A as its value. function getWrestling($style, $id) { $id=mysql_real_escape_string($id); if ($style=='singles') { $query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.manager_id = bio.id) WHERE ebw.bio_id = '$id'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ ?> <h2>Wrestling</h2> <table class="biotable" cellspacing="10px"> <tr class="biotablerowb"> <td class="biotableheadingb">Manager/Valet:</td> <td class="biotabledatab"><?php if (strlen ($manager) < 1) { print "N/A"; } else { print "$manager";}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Finisher:</td> <td class="biotabledatab"><?php if (strlen ($finisher) < 1) { print "N/A"; } else { print "$finisher";}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Setup:</td> <td class="biotabledatab"><?php if (strlen ($setup) < 1) { print "N/A"; } else { print "$setup";}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($music) < 1) { print "N/A"; } else { print "$music";}?></td> </tr> </table> <?php } }?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 6, 2010 Share Posted October 6, 2010 $manager, $finisher, $setup and $music are all undefined. $row['manager'], $row['finisher'], etc. would be where you need to look for values . . . Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 6, 2010 Author Share Posted October 6, 2010 Okay now I'm back to it only showing the information for the wrestlers that have a manager. function getWrestling($style, $id) { $id=mysql_real_escape_string($id); if ($style=='singles') { $query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.manager_id = bio.id) WHERE ebw.bio_id = '$id'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ ?> <h2>Wrestling</h2> <table class="biotable" cellspacing="10px"> <tr class="biotablerowb"> <td class="biotableheadingb">Manager/Valet:</td> <td class="biotabledatab"><?php if (strlen ($row['manager']) < 1) { print "N/A"; } else { print $row['manager'];}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Finisher:</td> <td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) { print "N/A"; } else { print $row['finisher'];}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Setup:</td> <td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) { print "N/A"; } else { print $row['manager'];}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($row['music']) < 1) { print "N/A"; } else { print $row['music'];}?></td> </tr> </table> <?php } }?> Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 7, 2010 Author Share Posted October 7, 2010 Does that help? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 7, 2010 Share Posted October 7, 2010 i believe your SQL is wrong, if you mean to also include records where ebw.bio_id = NULL (no manager) Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 8, 2010 Author Share Posted October 8, 2010 Explain please. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 the WHERE condition states WHERE ebw.bio_id = '$id' but what if bio_id has no match? then WHERE ebw.bio_id will be null. no? Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 8, 2010 Author Share Posted October 8, 2010 After doing some research and logic thinking I came up with the idea just to split it into two queries. Here's what I came up with however its saying that managerid is undefined. function getWrestling($style, $id) { $id=mysql_real_escape_string($id); if ($style=='singles') { $query = "SELECT ebw.manager_id AS managerid, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw LEFT JOIN efed_bio AS bio ON ( ebw.bio_id = bio.id) WHERE ebw.bio_id = $id"; $result = mysql_query($query) or die(mysql_error()); if($managerid != ''){ $query = "SELECT * FROM `efed_bio` WHERE id = '$managerid'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $manager = $row['charactername']; } else{ $manager = 'None'; } while ($row = mysql_fetch_array($result)){ ?> <h2>Wrestling</h2> <table class="biotable" cellspacing="10px"> <tr class="biotablerowb"> <td class="biotableheadingb">Manager/Valet:</td> <td class="biotabledatab"><?php echo $manager ?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Finisher:</td> <td class="biotabledatab"><?php if (strlen ($row['finisher']) < 1) { print "N/A"; } else { print $row['finisher'];}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Setup:</td> <td class="biotabledatab"><?php if (strlen ($row['setup']) < 1) { print "N/A"; } else { print $row['setup'];}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($row['music']) < 1) { print "N/A"; } else { print $row['music'];}?></td> </tr> </table> <?php } }?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 you performed the query, but you didn't grab the results using mysql_fetch_array, mysql_fetch_assoc or other. that's why $managerid is undefined. Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 8, 2010 Author Share Posted October 8, 2010 I have it. while ($row = mysql_fetch_array($result)){ Quote Link to comment Share on other sites More sharing options...
Xtremer360 Posted October 8, 2010 Author Share Posted October 8, 2010 So I have no idea what the issue is since I have it defined. Don't I? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 you defined $row, but where is $managerid defined? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 hint: after you define $row, you can define managerid like this: $managerid = $row['managerid']; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 8, 2010 Share Posted October 8, 2010 $managerid is not defined anywhere within that function. $managerid has to be passed to the function as a parameter, or its value assigned within the function for it to have a value. This function will do nothing. The value of $text is not available within the function; the value is not within the function's scope. $text = 'string of words'; function scope() { return $text; } echo scope(); This way the value is passed to the function as a parameter, and $text will have a valid value. function scope($parameter) { $text = $parameter; return $text; } echo scope('This is a string of text'); Does it make more sense now? 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.