Results 1 to 10 of 10

Thread: generate variable

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    New York
    Posts
    74

    generate variable

    Every time the winning team wins I would like to have this image appear after the winning team name. Now to determine the winning team is based on the highest runs.

    Take a look at this page to understand what I mean. Now please don't be fooled by is appearing after the winning team because the command isn't correct. It just appears on the bottom team or the home team.

    away = top team
    bottom = home.

    Here is the PHP code

    PHP Code:
    <?php
    $generate 
    '';

    $result mysql_query("SELECT * FROM boxscoreaway ORDER BY 'id' ASC"); 
    $away mysql_fetch_array($result);
        
    $result mysql_query("SELECT * FROM boxscorehome ORDER BY 'id' ASC"); 
    $home mysql_fetch_array($result);

        
    // the away team just began
        
    $generate .= '<tr style="background-color:eeeeee">
                  <td width="254"><table width="100%" border="0">
            <tr>
              <td id="team" width="40%">' 
    $away['team'] . '</td>
              <td align="left" width="60%">'
    ;
              if( 
    $away['winner'] != '' ) {
                  
    $generate .= '<img src="http://robbyzworld.com/personal/images/sports/nyy/winner.gif" />';
              }
              
              
    $generate .= '</td>
            </tr>
          </table></td>
                  <td width="30" id="RHE">' 
    $away['R'] . '</td>
                  <td width="30" id="RHE">' 
    $away['H'] . '</td>
                  <td width="30" id="RHE">' 
    $away['E'] . '</td>
                </tr>'
    ;
        
    // the away team just ended

        // the home team just began
        
    $generate .= '<tr style="background-color:eeeeee">
                  <td width="254"><table width="100%" border="0">
            <tr>
              <td id="team" width="40%">' 
    $home['team'] . '</td>
              <td align="left" width="60%">'
    ;
              if( 
    $home['winner'] != '' ) {
                  
    $generate .= '<img src="http://robbyzworld.com/personal/images/sports/nyy/winner.gif" />';
              }
                
    $generate .= '</td>
            </tr>
          </table></td>
                  <td width="30" id="RHE">' 
    $home['R'] . '</td>
                  <td width="30" id="RHE">' 
    $home['H'] . '</td>
                  <td width="30" id="RHE">' 
    $home['E'] . '</td>
                </tr>'
    ;
        
    // end the home team just ended

    echo $generate;

    ?>

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: generate variable

    just check if the away runs is higher than the home runs. if so, then the away team wins. otherwise, the home team wins.

    PHP Code:
    if($away['R'] > $home['R']){
      
    $winner "away";
    }elseif(
    $away['R'] == $home['R']){
      
    $winner "tie";
    }else{
      
    $winner "home";


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    New York
    Posts
    74

    Re: generate variable

    where do I put that code though?

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: generate variable

    just after your SQL queries, and before you're starting to output anything.. then, instead of checking if $away['winner'] is not equal to a null string, you just have to check if $winner is equal to "away"; then you need to change the same for the "home" part as well.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: generate variable

    Style point: you should never put HTML in strings. PHP is not Perl, it is an embedded scripting language. Just close the PHP block: ?>

    For anything non-trivial, you should really be using some sort of template system.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    New York
    Posts
    74

    Re: generate variable

    Thanks Kows!

    Penagate, what do you mean by html strings?

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: generate variable


  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    New York
    Posts
    74

    Re: generate variable

    why is echoing a whole chunk not a good thing?

    If you add an echo on each line isn't it more code?

  9. #9
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: generate variable

    it can be confusing and sloppy to use echo to output HTML. PHP is an embedded language; that means you embed into HTML -- not use it to output HTML. if it can be avoided, it should be. it makes your code twenty-million times easier to read (yes, really, that many times). it's probably faster (though, admittedly, probably not that much faster) this way, too.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    New York
    Posts
    74

    Re: generate variable

    ahh ok....

    I am still earning so once I conquer that then I will take the next step and try to make it so my coding is more proficient and easier to read.

    Thanks for the tips!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width