Forum Moderators: coopster

Message Too Old, No Replies

Show/hide a column if.

         

skoff

1:43 am on Mar 19, 2009 (gmt 0)

10+ Year Member



Hi guys!

I'm trying to do something but I don't know how to do it. This is why i'm here!

I have hockey games results. What i want to do is if the game goes in overtime i want to show the column "overtime" but if there was no overtime during the game i dont want to see this column. How can i do this?

Table : schedule
columns : home,away,homepoints,awaypoints,homeotpoints,awayotpoints

blang

2:34 am on Mar 19, 2009 (gmt 0)

10+ Year Member



I don't see a column named `overtime` listed. Are you referring to a HTML TABLE element cell?

skoff

3:26 am on Mar 19, 2009 (gmt 0)

10+ Year Member



yes well i want to show these informations in a html table. And yes sorry there is a column named overtime

coopster

11:26 am on Mar 19, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



As you loop through your hockey game result set you check to see if there was overtime, if so, append that field to your table. If not, either leave the column out entirely or insert a blank space for that column value.

skoff

1:49 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



i know that's what i have to do... the thing is that i dont know how to write this in a query.... and i want to leave the column out

coopster

2:00 pm on Mar 19, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Oh, OK. I misunderstood you. You are at square one, wondering how to start. And it sounds like the data is in a database table. First, develop your query statement. You want to select data from the table. So, you need to develop a SELECT query statement.

skoff

2:23 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



yes i know how to do this i just need help with my query where I need to say that if column overtime = yes you have to show the result that are in this column if overtime = no you just leave the column out.

blang

4:16 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



Just getting back to this thread.

Hopefully you haven't actually used a CHAR type column to store the strings "YES" or "NO" (although that's not the worst thing in the world to have done) - use a BOOL (TINYINT(1)) type column to store a 0 or 1 state instead.

The query should just retrieve whatever is in the table, as long as there is a value in the `overtime` field, then your PHP code should look at the returning values in the resultset and create a conditional based on this, e.g.


//... executed query at this point, staring loop through records
while( $row= mysql_fetch_assoc($resultset) ) {
// ... whatever process you go through here to create the data output
if ( $row['overtime'] === 0 ) {
// no overtime
// show a "NO" or leave the TD cell blank (use  )
} else {
// there was overtime, ooh exciting!
// show a "YES" or something in the cell
}
}

Alternatively, you could just leave the values "YES" or "NO" in the database and print out the column.

Is that what you're looking for?

skoff

2:54 am on Mar 20, 2009 (gmt 0)

10+ Year Member



yes and thanks! and i want to know how can i just dont show the column overtime if there is no overtime?

skoff

3:37 am on Mar 20, 2009 (gmt 0)

10+ Year Member



there is another thing i want to know if you can help me with. How can i make an addition with some value. I made a query but its not working instead of make an addition it replace the value with what i want to make an addition. Example :
$query = UPDATE stats SET game='game'+1 where player='Gino'

What i want to do with this query is to add a game in my table. So if Gino played 12 games and i do this query then i would have the result of 13. But instead of getting 13 i get 1? Why?

Thanks guys for your help!