October 8, 201016 yr It has the bio_id of the wrestler and what it's supposed to do is get the manager_id and then take it to the efed_bio table and match that to the same integer and when it finds a match record then get that person's charactername and if there is a 0 for the value inside of manager_id then it says "N/A" 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 } }?>
October 8, 201016 yr At a quick glance it looks ok. Do you get any error messages? Only thing I did notice, you have quotes around the $id in the WHERE clause. I'd assume $id is a number, if so you don't need to have quotes around it. WHERE ebw.bio_id = $id"; Might be worth trying the SQL query in phpmyadmin or on the command line to see if it works (with the join etc).
October 8, 201016 yr Try this. It seems you were missing the closing curly brace ("}") for the line, "function getWrestling($style, $id) {" note: remember that tabs and white-space are your best friends in coding <?php 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)) { echo(' <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> '); } } } ?>
October 8, 201016 yr @Jordan Well spotted Aha thanks. Some PHP errors just need a fresh pair of eyes to find them.
October 8, 201016 yr Author I don't think its it because here's the entire function it its entirety. 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.bio_id = bio.id) WHERE ( ebw.bio_id = '$id') AND ( ebw.manager_id = bio.id)"; $result = mysql_query($query) or die(mysql_error()); echo $query; 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['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 } }?> <?php if ($style=='tagteam') { } ?> <? if ($style=='manager') { $sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'"; $re = mysql_query($sql); $row = mysql_fetch_assoc($re); extract($row); ?> <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">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($music) < 1) { print "N/A"; } else { print "$music";}?></td> </tr> </table> <?php } ?> <? if ($style=='staff') { $sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'"; $re = mysql_query($sql); $row = mysql_fetch_assoc($re); extract($row); ?> <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">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($music) < 1) { print "N/A"; } else { print "$music";}?></td> </tr> </table> <?php } ?> <? if ($style=='stable') { } } Aha thanks. Some PHP errors just need a fresh pair of eyes to find them.
October 8, 201016 yr I don't think its it because here's the entire function it its entirety. 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.bio_id = bio.id) WHERE ( ebw.bio_id = '$id') AND ( ebw.manager_id = bio.id)"; $result = mysql_query($query) or die(mysql_error()); echo $query; 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['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 } }?> <?php if ($style=='tagteam') { } ?> <? if ($style=='manager') { $sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'"; $re = mysql_query($sql); $row = mysql_fetch_assoc($re); extract($row); ?> <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">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($music) < 1) { print "N/A"; } else { print "$music";}?></td> </tr> </table> <?php } ?> <? if ($style=='staff') { $sql = "SELECT * FROM `efed_bio_wrestling` WHERE bio_id = '$id'"; $re = mysql_query($sql); $row = mysql_fetch_assoc($re); extract($row); ?> <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">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($music) < 1) { print "N/A"; } else { print "$music";}?></td> </tr> </table> <?php } ?> <? if ($style=='stable') { } } Then have you got the exact error message you're getting? However as I already said you really need to work on formatting your code more neatly.
October 8, 201016 yr Author I'm not getting an error message. Nothing is appearing for that function.
October 8, 201016 yr Do you have a PHP error log? Have you got errors turned on? Also did you try running the query in phpmyadmin or cmd line? I agree with code formatting thing... Try using an IDE/editor that indents for you perhaps.
October 8, 201016 yr Author I have error reporting turned on and none are being reported and when I run it in phpmyadmin no results are being returned for the echoed query. Do you have a PHP error log? Have you got errors turned on? Also did you try running the query in phpmyadmin or cmd line? I agree with code formatting thing... Try using an IDE/editor that indents for you perhaps.
October 8, 201016 yr I have error reporting turned on and none are being reported and when I run it in phpmyadmin no results are being returned for the echoed query. Well then the problem is your query. Look up some documentation about what you want the query to do because to me it looks overly complicated.
October 8, 201016 yr Change your query to a LEFT JOIN Looks like Jock's right to me Edit: Also, 'ON's can be dodgy. I'd check that.
October 8, 201016 yr Author Okay this works, however, the value of manage_id needs to be compared to bio_id and then when it finds a matching row then get the bio.charactername field. SELECT ebw.manager_id AS manager, 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 = 6
October 8, 201016 yr Author I came up with this and I'm getting closer 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 } }?>
October 9, 201016 yr I'm pretty drunk right now but it looks like youre not actually pulling out a field called 'charactername'.
October 9, 201016 yr Author That's always fun but its supposed to when it matches ewb.managerid to bio.id then get that row's charactername.
October 9, 201016 yr Author $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()); $row = mysql_fetch_assoc($result); $managerid = $row['managerid']; This works however I need to figure out with the managerid if its 0 then that's when it puts None
Create an account or sign in to comment