Jump to content

Hiding some data


BelowZero

Recommended Posts

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.