Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Stuck defining variable in existing code

    hi there,
    im not the best by far at php so newbie question time as i just cant seem to figure out how to solve this issue

    below is section of code im trying to work with. Ive not coded this its been left over from our old coder a few years back (maybe more) and the php - to me anyway - looks slightly out of date. My aim is to bring it up to scratch but in time also re-write the code so its totally upto date.

    Anyway i keep getting the following error - Notice: Undefined variable: league_id in /home/-------/public_html/----/instellingen.inc on line 812 (which for the purpose of this will actually be line 5)

    I have pasted the whole function into the tags - the purpose of this part of code is to query the database for the last 3 fixtures played and then return the data into the tables. I know the connection and most of the code parses well and correctly in other sections of the site - but i cant seem to figure a way to define the variable so it displays and the error goes away.

    Ive tried multiple ways and read many sites including this one but still to no avail - im sure ive been trying it correctly but getting the syntax wrong or something else within the function is stopping it.

    PHP Code:
    function show_last_results($limit=3, $league="", $wide=""){

        //global $league;

        if ($league_id=="")$league_id = get_league_id($league);

        $sql = "SELECT league_id, hometeam_id, awayteam_id, home_result, away_result, game_id ".
                "FROM fixtures_result ".
                "WHERE home_result IS NOT NULL ";
                if ($league!="all"){
                    $sql .= "AND league_id='" . mysql_real_escape_string($league_id) . "' ";
                }
                $sql .= "ORDER BY game_time DESC LIMIT $limit";

                //echo $sql;
        $result = mysql_query($sql);
        //$num_rows = mysql_num_rows($result);
        //if ($num_rows>0)
        $colourclass = "fixturesLightRow";
        while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
            $league = urlencode(get_league_name($row[0]));
            if ($row[0] == 41){
                $show_by = "user";
            }else{
                $show_by = "team";
            }
            
            if ($show_by == "team"){
                $hometeam = get_team_information($row[1]);
                $awayteam = get_team_information($row[2]);
                $hometeamname = urlencode($hometeam[1]);
                $awayteamname = urlencode($awayteam[1]);
            }else{
                $hometeam[1] = get_user_name($row[1]);
                $awayteam[1] = get_user_name($row[2]);
                $hometeam[3] = "";
                
            }
            ?>
            <tr class="<? echo $colourclass;?>">
                <td <?if ($wide!='small'){echo 'class="awayTeamNameCell"';}else{echo 'class="smallleague"';}?>>
                <? if ($show_by == "team"){?>
                    <a href="team.php?team=<? echo $hometeamname.'&league='.$league;?>"><? if ($wide!='small'){echo substr($hometeam[1],0,23);}else{echo substr($hometeam[1],0,16);}?></a>
                <? }else{
                    echo 
    $hometeam[1];    
                }    
                
    ?>
                </td>
                
                <td class="GoalDiff"><? echo $row[3] . "-" $row[4];?></td>
                
                <td <?if ($wide!='small'){echo 'class="awayTeamNameCell"';}else{echo 'class="smallleague"';}?>>
                
                <? if ($show_by == "team"){?>
                    <a href="team.php?team=<? echo $awayteamname.'&league='.$league;?>"><? if ($wide!='small'){echo substr($awayteam[1],0,23);}else{echo substr($awayteam[1],0,16);}?></a>
                <? }else{
                    echo 
    $awayteam[1];    
                }
                
    ?>
                </td>
                <?
                
    if ($wide!="small"){
                
    ?>
                    <td class="venueCell">
                        <? echo substr($hometeam[3],0,24);?>
                    </td>
                    <td>
                        <a href="leaguetable.php?league=<? echo urlencode($league);?>"><? echo urldecode($league);?></a>
                    </td>
                    <td class="matchArticleCell">
                        <a href="javascript:popUp_big('show_fixture_details.php?gameid=<? echo $row[5];?>&league=<? echo $league;?>&action=view&menu=not')">view</a>
                    </td>
                <?
                
    }
                
    ?>
            </tr>
            <?
            
    if ($colourclass == "fixturesLightRow"){
                
    $colourclass "fixturesDarkRow";
            }elseif (
    $colourclass == "fixturesDarkRow"){
                
    $colourclass "fixturesLightRow";
            }
        }
    }
    any suggestions on how i get around this?
    cheers in advance
    Last edited by angelclawdust; 06-11-2013 at 11:23 AM. Reason: Changed topic prefix to Resolved

  • #2
    Junsee
    Guest
    what the error is say is that if the if statement is not met then you have an variable that is never used, it not an error, just a warning ... I think there is a programming joke about that


    EDIT
    Wait sorry, I misread that. You never tell the program what the value of $league_id is (the varaible is not set) , but then its asked to find a varaible and run a logic statement on it.

    PHP Code:
    #You need, something like:
    # $league_id = 1;
    # or
    # $league_id = "";

    if ($league_id=="")$league_id get_league_id($league); 
    otherwise just remove the if

    PHP Code:
    $league_id get_league_id($league); 
    Last edited by Junsee; 06-11-2013 at 10:42 AM.

  • Users who have thanked Junsee for this post:

    angelclawdust (06-11-2013)

  • #3
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Junsee View Post
    what the error is say is that if the if statement is not met then you have an variable that is never used, it not an error, just a warning ... I think there is a programming joke about that


    EDIT
    Wait sorry, I misread that. You never tell the program what the value of $league_id is (the varaible is not set) , but then its asked to find a varaible and run a logic statement on it.

    PHP Code:
    #You need, something like:
    # $league_id = 1;
    # or
    # $league_id = "";

    if ($league_id=="")$league_id get_league_id($league); 
    otherwise just remove the if

    PHP Code:
    $league_id get_league_id($league); 
    ahh nice one - i knew it would be something simple lol

    i went with
    PHP Code:
    if ($league_id "")$league_id get_league_id($league); 
    couldnt remove the "if" its connected with the rest of the page (its like a functions page)
    which did the trick nicely so thankyou Junsee
    now onto the other errors/notices that'll crop up


  •  

    Posting Permissions

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