Jump to content

If statement not working


Recommended Posts

So the issue I'm having here is that when champion_id, contender1_id, contender2_id, and contender3_id  values are 0 then it DOES NOT echo Vacant and TBD as it should be, however when they are values other than 0 then it does correctly show the person's name. What am I doing wrong for it to not display the Vacant or TBD?


$query = "SELECT 
    title_champions.champion_id AS champion_id,
    title_champions.contender1_id AS contender1_id,
    title_champions.contender2_id AS contender2_id,
    title_champions.contender3_id AS contender3_id,
    champion.character_name AS champion,
    contender1.character_name AS contender1,
    contender2.character_name AS contender2,
    contender3.character_name AS contender3
     LEFT JOIN titles 
          ON title_champions.title_id = titles.id
     LEFT JOIN characters AS champion
          ON title_champions.champion_id = champion.id
     LEFT JOIN characters AS contender1
          ON title_champions.contender1_id = contender1.id
     LEFT JOIN characters AS contender2
          ON title_champions.contender2_id = contender2.id
     LEFT JOIN characters AS contender3
          ON title_champions.contender3_id = contender3.id
$result = mysqli_query ( $dbc, $query ); // Run The Query


            while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
			echo '<tr><td>' . $row['title_name'] . '</td><td>';
				if($row['champion_id'] !== 0){echo $row['champion'];}else{echo "Vacant";}
			echo '</td><td>';
				if($row['contender1_id'] !== 0){echo $row['contender1'];}else{echo "TBD";}
			echo '</td><td>';
				if($row['contender2_id'] !== 0){echo $row['contender2'];}else{echo "TBD";}
			echo '</td><td>';
				if($row['contender3_id'] !== 0){echo $row['contender3'];}else{echo "TBD";}
			echo '</td><td style="text-align:center;"><img src="img/notepad.png" class="edit" rel="' . $row['id'] . '"/></td></tr>';

Link to comment
Share on other sites

I placed the following right inside the while loop and nothing echos out. I don't know why because I double checked many times all values are 0 inside of the database.


echo $row['champion_id'];
                echo $row['contender1_id'];
                echo $row['contender2_id'];
                echo $row['contender3_id'];

Link to comment
Share on other sites

okay so now you know your problem...i've had issues in the past with default values in tables not appearing...you can change the field to a varchar and manually enter in a 0. but other than that im not sure what causes that to happen

Link to comment
Share on other sites

Just wanted to say that the issue was fixed. When I did a var_dump it showed that those variables where strings even though te db field type were integers and originally had if($row['champion_id'] !== 0") so I had to change it to this if($row['champion_id'] !== "0").

Link to comment
Share on other sites


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.