Jump to content

While Statement having issues


Xtremer360

Recommended Posts

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 } }?>

Link to comment
https://forums.phpfreaks.com/topic/215263-while-statement-having-issues/
Share on other sites

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 } }?>

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 } }?>

$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?

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.