BelowZero Posted March 14, 2011 Share Posted March 14, 2011 When I display my database entries, I want to hide some of the data. As you can see in this example: http://www.beat-the-spread.net/week1.php What I'd like to do is leave all the cells blank where the spread is zero. Here's the code I'm using: while($row = mysql_fetch_array( $result )) { $i=1; if ($row['game_id']='$i') { echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['team_name']; echo "</td><td>"; echo $row['owner']; echo "</td><td>"; echo $row['pt_spread']; echo "</td><td>"; echo $row['team_pts']; echo "</td><td>"; echo $row['team_bet']; echo "</td><td>"; echo $row['team_cover']; echo "</td><td>"; echo $row['owner_pts']; echo "</td></tr>"; if ($table_row_count % 2 && $table_row_count != 0) { echo ' <tr style="height: 8px"></tr> '; } $table_row_count++; } $i++; } echo "</table>"; I've been fooling with this for a couple hours and can't seem to find a decent way to do this. Can anybody help with this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/230651-hiding-some-data/ Share on other sites More sharing options...
MadLittleMods Posted March 15, 2011 Share Posted March 15, 2011 use this... while($row = mysql_fetch_array( $result )) { $i=1; if ($row['game_id']='$i') { if($row['pt_spread'] == 0) { $row['pt_spread'] = "" } echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['team_name']; echo "</td><td>"; echo $row['owner']; echo "</td><td>"; echo $row['pt_spread']; echo "</td><td>"; echo $row['team_pts']; echo "</td><td>"; echo $row['team_bet']; echo "</td><td>"; echo $row['team_cover']; echo "</td><td>"; echo $row['owner_pts']; echo "</td></tr>"; if ($table_row_count % 2 && $table_row_count != 0) { echo ' <tr style="height: 8px"></tr> '; } $table_row_count++; } $i++; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/230651-hiding-some-data/#findComment-1187555 Share on other sites More sharing options...
.josh Posted March 15, 2011 Share Posted March 15, 2011 fyi this... if ($row['game_id']='$i') ...always evaluates true. = is the assignment operator. == is the comparison operator. Also, '$i' will assign the literal string '$i'. If you want to compare it to the value of the $i variable, you need to use double quotes. PHP does not parse variables in single quotes. Better yet, don't wrap it in quotes at all, since it is not necessary and is technically less efficient. if ($row['game_id']==$i) But on the note of $i...what exactly is your intention with $i and that condition? Because as it stands now, for each iteration of the loop, you... - set it to 1 - check if $row['game_id'] equals one (pending fixes above) - increment $i by 1 So something isn't adding up right here. If it is "working" for you as it is right now, then there is no point in having that $i stuff at all. But if you fix the condition as I have mentioned...then either the assignment or increment is pointless, as they cancel each other out. Quote Link to comment https://forums.phpfreaks.com/topic/230651-hiding-some-data/#findComment-1187557 Share on other sites More sharing options...
BelowZero Posted March 15, 2011 Author Share Posted March 15, 2011 Thanks MadLittleMods. I tried that and couldn't get it to work until I used "==" instead of "=". Now it works fine. Crayon Violent, I'm new to all this so I appreciate your comments. The database is set up with a "week_id", a "game_id" and a "place_id" to indicate either home team (1) or away team (2). I struggled with getting this to print a weekly schedule correctly for several days before coming up with this code that works. The $i only has to be a 1 or a 2 since they represent the home team and away team. I wanted to print a separator between each game so that's why after $i++, I reset it back to 1 for the next loop. I understand your point, but if I change the code to if ($row['game_id']==$i) it only prints 1 game. In fact, that's the way I coded it at first. When I use if ($row['game_id']='$i') it loops through all the games for that week, which is what I need. I'm going to try getting rid of the $i completely and just use a 1 in it's place and see it that works. Quote Link to comment https://forums.phpfreaks.com/topic/230651-hiding-some-data/#findComment-1187585 Share on other sites More sharing options...
BelowZero Posted March 15, 2011 Author Share Posted March 15, 2011 ...or just get rid of the if statement completely, which worked fine. Don't know where I came up with that anyway. Must have been a long night... Quote Link to comment https://forums.phpfreaks.com/topic/230651-hiding-some-data/#findComment-1187592 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.