Xtremer360 Posted May 25, 2011 Share Posted May 25, 2011 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 titles.title_name, titles.id, 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 FROM title_champions 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 ORDER BY titles.title_name"; $result = mysqli_query ( $dbc, $query ); // Run The Query <?php 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/ Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 1. have you tried echoing the value of $row['champion_id']? 2. what actually happens when the value is 0? 3. are you inserting the contender_id into your db as 0 or blank? Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220196 Share on other sites More sharing options...
Xtremer360 Posted May 25, 2011 Author Share Posted May 25, 2011 the values are have a type of INT and also have a default value of 0. Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220197 Share on other sites More sharing options...
Xtremer360 Posted May 25, 2011 Author Share Posted May 25, 2011 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']; Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220198 Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220201 Share on other sites More sharing options...
Xtremer360 Posted May 25, 2011 Author Share Posted May 25, 2011 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"). Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220251 Share on other sites More sharing options...
Xtremer360 Posted May 25, 2011 Author Share Posted May 25, 2011 Dang it won't let me edit that last post. The fix was from if($row['champion_id'] !== 0) to if($row['champion_id'] !== "0") Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220259 Share on other sites More sharing options...
fugix Posted May 26, 2011 Share Posted May 26, 2011 ah, glad you figured it out Quote Link to comment https://forums.phpfreaks.com/topic/237453-if-statement-not-working/#findComment-1220371 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.