Jump to content

help with displaying php echo in a table


treybraid

Recommended Posts

for some reason it will not render to the row... ive added the php echo to the row in question and it runs with the top row... can someone take a look and let me know what i am doing wrong...

 

thanks

trey

 

here is the code... the php echo in bold red should show up on the next row; but, it doesnt...

 

<?php

/**

* @version $Id: mod_gridiron_game_results.php, v1.5.0 March 2011 01:32:15

* @author Fastball Productions

* @package Gridiron

* @copyright Copyright © 2011 Fastball Productions

* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL

*/

 

// no direct access

defined('_JEXEC') or die('Restricted access');

 

$db =& JFactory::getDBO();

 

// get the module parameters

$heading = $params->get( 'heading', '' );

$showpast = $params->get( 'showpast', '1' );

$numberpast = $params->get( 'numberpast', '1' );

$linkboxscore = $params->get( 'linkboxscore', '1' );

$shownextgame = $params->get( 'nextgame', '1' );

$numbernext = $params->get( 'numbernext', '1' );

$linknext = $params->get( 'linknext', '1' );

$seasonid = $params->get( 'seasonid', '1' );

$gametypes = $params->get( 'gametypes', '1' );

$teamids = $params->get( 'teamids', '' );

$leagueids = $params->get( 'leagueids', '' );

$divisionids = $params->get( 'divisionids', '' );

 

if (is_array($gametypes)) {

$gametypes = implode(',', $gametypes);

}

if (is_array($teamids)) {

$teamids = implode(',', $teamids);

}

if (is_array($leagueids)) {

$leagueids = implode(',', $leagueids);

}

if (is_array($divisionids)) {

$divisionids = implode(',', $divisionids);

}

 

// if there is a league configured, get the teams within the league/division;

if ($teamids == '' && ($divisionids || $leagueids)) {

if ($divisionids) {

// get a listing of all team ID's that belong in the league and division;

$sql = "SELECT id FROM #__gridiron_team WHERE (FIND_IN_SET(divisionid, '$divisionids'))";

}

else {

// get a listing of all team ID's that belong in the league;

$sql = "SELECT id FROM #__gridiron_team WHERE (FIND_IN_SET(leagueid, '$leagueids'))";

}

$db->setQuery($sql);

$rows = $db->loadResultArray();

$teamids = implode(',', $rows);

}

else if ($teamids == '') {

// get the default team (single team component only);

$db->setQuery("SELECT id FROM #__gridiron_team WHERE (defaultteam = 1)");

$teamids = $db->loadResult();

}

 

// get the last x number of games played and the results;

$db->setQuery("SELECT a.*, a.hometeam AS hometeamid, a.visitingteam AS visitingteamid,

DATE_FORMAT(a.gamedatetime, '%a, %M %D') AS gamedate,

DATE_FORMAT(a.gamedatetime, '%l:%i %p') As gametime,

h.name AS hometeam,

v.name AS visitingteam,

b.finalv, b.finalh

FROM #__gridiron_schedule AS a

LEFT JOIN #__gridiron_team AS h ON a.hometeam = h.id

LEFT JOIN #__gridiron_team AS v ON a.visitingteam = v.id

LEFT JOIN #__gridiron_boxscore AS b ON a.id = b.gameid

WHERE (a.scored = 1 AND a.season = {$seasonid} AND (FIND_IN_SET(a.gametype, '$gametypes')) AND (FIND_IN_SET(a.hometeam, '$teamids') OR FIND_IN_SET(a.visitingteam, '$teamids')) AND a.gamedatetime < now())

GROUP BY a.id

ORDER BY a.gamedatetime DESC LIMIT 0, {$numberpast}");

$pastgames = $db->loadObjectList();

 

// get the next x number of games scheduled;

$db->setQuery("SELECT a.*, a.hometeam AS hometeamid, a.visitingteam AS visitingteamid,

DATE_FORMAT(a.gamedatetime, '%a, %M %D') AS gamedate,

DATE_FORMAT(a.gamedatetime, '%l:%i %p') As gametime,

h.name AS hometeam,

v.name AS visitingteam,

t.description AS gametype

FROM #__gridiron_schedule AS a

LEFT JOIN #__gridiron_team AS h ON a.hometeam = h.id

LEFT JOIN #__gridiron_team AS v ON a.visitingteam = v.id

LEFT JOIN #__gridiron_gametype AS t ON a.gametype = t.id

LEFT JOIN #__gridiron_location AS l ON a.location = l.id

WHERE (a.scored = 0 AND a.season = {$seasonid} AND (FIND_IN_SET(a.gametype, '$gametypes')) AND (FIND_IN_SET(a.hometeam, '$teamids') OR FIND_IN_SET(a.visitingteam, '$teamids')) AND DATE_ADD(a.gamedatetime, INTERVAL 3 HOUR) > now())

GROUP BY a.id

ORDER BY a.gamedatetime ASC LIMIT 0, {$numbernext}");

$nextgames = $db->loadObjectList();

?>

<table width="100%" border="0" align="center">

<?php if ($showpast && $numberpast > 0) { ?>

<tr>

<td colspan="2" style="text-align:center;"><b><?php echo $heading;?></b></td>

</tr>

<tr>

<td width="43%"><b><u>Matchup</u></b></td>

<td width="57%" style="text-align:center;"><b><u>Result</u></b></td>

</tr>

<?php foreach ($pastgames as $past) { ?>

<tr>

<td>

<?php echo $past->visitingteam;?> vs.<br /><?php echo $past->hometeam;?>

</td>

<td style="text-align:center;">

<?php if ($linkboxscore) { ?>

<a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=boxscore&id=$past->id");?>"><?php echo $past->finalv;?><br /><?php echo $past->finalh;?></a>

<?php } else { ?>

<?php echo $past->finalv;?><br /><?php echo $past->finalh;?>

        </td>

<?php } ?>

</tr>

<tr>

<td colspan="2"></td>

</tr>

<?php } ?>

<?php } ?>

<?php if ($shownextgame && $numbernext > 0 && $nextgames) { ?>

<tr>

<td colspan="2"><b><u>Next Game</u></b></td>

       

</tr>

<?php foreach ($nextgames as $next) { ?>

<?php $next->visitingteam == '' ? $next->visitingteam = 'TBA':$next->visitingteam = $next->visitingteam;?>

<?php $next->hometeam == '' ? $next->hometeam = 'TBA':$next->hometeam = $next->hometeam;?>

<tr>

<td colspan="2">

<?php if ($linknext) { ?>

<?php if ($next->visitingteam == 'TBA') { ?>

<?php echo $next->visitingteam;?>

<?php } else { ?>

<a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=schedule&id=$next->visitingteamid");?>"><?php echo $next->visitingteam;?></a>

<?php } ?>

vs.

<?php if ($next->hometeam == 'TBA') { ?>

<?php echo $next->hometeam;?>

<?php } else { ?>

<a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=schedule&id=$next->hometeamid");?>"><?php echo $next->hometeam;?></a>

<?php } ?>

<?php } else { ?>

<?php echo $next->visitingteam;?> vs. <?php echo $next->hometeam;?>

</td>

</tr>

<tr>

  <td colspan="2"><?php } ?><?php echo $next->gamedate . ' ' . $next->gametime;?> </td> 

  </tr>

<?php } ?>   

<?php } ?>   

</table>

 

[attachment deleted by admin]

Link to comment
Share on other sites

You must be using DreamWeaver or some other CRAP editor. All of those opening/closing PHP tags are a complete waste and make reviewing code 10 times harder than it should be.

After taking out all of that drap I think the problem is that you have a closing curly brace "}" right before you try to echo the gamedate and gametime. That brace is used to close an else condition code block - Which is just odd. That means the game date/time is supposed to be displayed no matter if that IF/ELSE condition is true or false. But, if the true condition occurs the game date/time would not be displayed in a table cell.

 

There are just so many embedded if/else statements and all the embedded PHP/HTML code it is near impossible to follow the logic. I would highly suggest you do all the "logic" in the start of the page to define the output, then just use echos in the HTML to put the output in the proper places. Plus, you should consider using proper indenting to make the flow of the code apparent.

 

EDIT: One last thing: Comments! Use them, they are your friend.

Link to comment
Share on other sites

mj i am using dreamweaver which i enjoy using quite a bit... and i am editing someone else's code on a 3rd party sports component i bought... the issue when viewed in dreamweaver is the echo is in a row yet it stays in the row above it with the other information....

 

trey

Link to comment
Share on other sites

mj i am using dreamweaver which i enjoy using quite a bit... and i am editing someone else's code on a 3rd party sports component i bought... the issue when viewed in dreamweaver is the echo is in a row yet it stays in the row above it with the other information....

 

As I stated, the code is not correct for the if/else branches. The opening of that row is within the ELSE condition above. So, if the IF condition is true the date/time will be included in the previous row.

Link to comment
Share on other sites

I also see some other HTML poblems that will result from your code:

 

      <td style="text-align:center;">
      <?php if ($linkboxscore) { ?>
      <a href="<?php echo JRoute::_("index.php?option=com_gridiron&view=boxscore&id=$past->id");?>"><?php echo $past->finalv;?><br /><?php echo $past->finalh;?></a>
      <?php } else { ?>
      <?php echo $past->finalv;?><br /><?php echo $past->finalh;?>
        </td>

Look what would happen if that IF statement results in TRUE - there would be no closing </TD> tag because you only put the closing tag within the ELSE statement. I' walking through the code now and will post a rewrite momentarily.

 

But, the reason for these errors is as I alluded to previously - with all the IF/ELSE conditions and opening/closing PHP tags it is near impossible to follow the flow to spot these problems

Link to comment
Share on other sites

Here is a complete rewrite of that code which, hopefully is more readable. It definitely has improved logic. For example, the previous code was always running the queries to get past/future games even if $showpast or $shownextgame were false. If they were false the code didn't use the queries data. If you are not going to use the data - don't query it.

 

I'm also sure there are some syntax errors since I couldn't test it without an appropriate database.

 

<?php
/**
* @version $Id: mod_gridiron_game_results.php, v1.5.0 March 2011 01:32:15
* @author Fastball Productions
* @package Gridiron
* @copyright Copyright (C) 2011 Fastball Productions
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

$db =& JFactory::getDBO();

// get the module parameters
$heading      = $params->get( 'heading', '' );
$showpast     = $params->get( 'showpast', '1' );
$numberpast   = $params->get( 'numberpast', '1' );
$linkboxscore = $params->get( 'linkboxscore', '1' );
$shownextgame = $params->get( 'nextgame', '1' );
$numbernext   = $params->get( 'numbernext', '1' );
$linknext     = $params->get( 'linknext', '1' );
$seasonid     = $params->get( 'seasonid', '1' );
$gametypes    = $params->get( 'gametypes', '1' );
$teamids      = $params->get( 'teamids', '' );
$leagueids    = $params->get( 'leagueids', '' );
$divisionids  = $params->get( 'divisionids', '' );

if (is_array($gametypes))   { $gametypes = implode(',', $gametypes); }
if (is_array($teamids))     { $teamids = implode(',', $teamids); }
if (is_array($leagueids))   { $leagueids = implode(',', $leagueids); }
if (is_array($divisionids)) { $divisionids = implode(',', $divisionids); }

// if there is a league configured, get the teams within the league/division;
if ($teamids == '')
{
   if ($divisionids)
   {
      // get a listing of all team ID's that belong in the league and division;
      $sql = "SELECT id FROM #__gridiron_team WHERE (FIND_IN_SET(divisionid, '$divisionids'))";
   }
   elseif ($leagueids)
   {
      // get a listing of all team ID's that belong in the league;
      $sql = "SELECT id FROM #__gridiron_team WHERE (FIND_IN_SET(leagueid, '$leagueids'))";
   }
   else
   {
       // get the default team (single team component only);
       $sql = "SELECT id FROM #__gridiron_team WHERE defaultteam = 1";
   }
   $db->setQuery($sql);
   $teamids = implode(',', $db->loadResultArray());
}

//Generate HTML for past games
$pastGamesHTML = '';
if ($showpast && $numberpast > 0)
{
    // get the last x number of games played and the results;
    $query = "SELECT a.*, a.hometeam AS hometeamid, a.visitingteam AS visitingteamid,
                     DATE_FORMAT(a.gamedatetime, '%a, %M %D') AS gamedate,
                     DATE_FORMAT(a.gamedatetime, '%l:%i %p') As gametime,
                     h.name AS hometeam, v.name AS visitingteam, b.finalv, b.finalh
              FROM #__gridiron_schedule AS a
              LEFT JOIN #__gridiron_team AS h ON a.hometeam = h.id
              LEFT JOIN #__gridiron_team AS v ON a.visitingteam = v.id
              LEFT JOIN #__gridiron_boxscore AS b ON a.id = b.gameid
              WHERE (a.scored = 1
                       AND a.season = {$seasonid}
                       AND (FIND_IN_SET(a.gametype, '$gametypes'))
                       AND (FIND_IN_SET(a.hometeam, '$teamids')
                            OR FIND_IN_SET(a.visitingteam, '$teamids'))
                AND a.gamedatetime < now())
              GROUP BY a.id
              ORDER BY a.gamedatetime DESC LIMIT 0, {$numberpast}"
    $db->setQuery($query);
    $pastgames = $db->loadObjectList();

    $pastGamesHTML .= "  <tr>\n";
    $pastGamesHTML .= "    <td colspan='2' style='text-align:center;'><b>{$heading}</b></td>\n";
    $pastGamesHTML .= "  </tr>\n";
    $pastGamesHTML .= "  <tr>\n";
    $pastGamesHTML .= "    <td width='43%'><b><u>Matchup</u></b></td>\n";
    $pastGamesHTML .= "    <td width='57%' style='text-align:center;'><b><u>Result</u></b></td>\n";
    $pastGamesHTML .= "  </tr>\n";

    foreach ($pastgames as $past)
    {
        $final = "{$past->finalv}<br />{$past->finalh}";
        if($linkboxscore)
        {
            $href  = JRoute::_("index.php?option=com_gridiron&view=boxscore&id=$past->id");
            $final = " <a href='{$href}'>$final</a>";
        }
        $pastGamesHTML .= "  <tr>\n";
        $pastGamesHTML .= "    <td>{$past->visitingteam;} vs.<br />{$past->hometeam}</td>\n";
        $pastGamesHTML .= "    <td style='text-align:center;'>\n";
        $pastGamesHTML .= "    <td>{$final}</td>";
        $pastGamesHTML .= "  </tr>\n";
    }
    //Add Separator
    $pastGamesHTML .= "  <tr>\n";
    $pastGamesHTML .= "    <td colspan='2'></td>\n";
    $pastGamesHTML .= "  </tr>\n";
}

//Generate HTML for past games
$nextGamesHTML = '';
if ($shownextgame && $numbernext > 0 && $nextgames)
{
    // get the next x number of games scheduled;
    $query = "SELECT a.*, a.hometeam AS hometeamid, a.visitingteam AS visitingteamid,
                     DATE_FORMAT(a.gamedatetime, '%a, %M %D') AS gamedate,
                     DATE_FORMAT(a.gamedatetime, '%l:%i %p') As gametime,
                     h.name AS hometeam, v.name AS visitingteam, t.description AS gametype
              FROM #__gridiron_schedule AS a
              LEFT JOIN #__gridiron_team AS h ON a.hometeam = h.id
              LEFT JOIN #__gridiron_team AS v ON a.visitingteam = v.id
              LEFT JOIN #__gridiron_gametype AS t ON a.gametype = t.id
              LEFT JOIN #__gridiron_location AS l ON a.location = l.id
              WHERE (a.scored = 0
                       AND a.season = {$seasonid}
                       AND (FIND_IN_SET(a.gametype, '$gametypes'))
                       AND (FIND_IN_SET(a.hometeam, '$teamids')
                            OR FIND_IN_SET(a.visitingteam, '$teamids'))
                AND DATE_ADD(a.gamedatetime, INTERVAL 3 HOUR) > now())
              GROUP BY a.id
              ORDER BY a.gamedatetime ASC LIMIT 0, {$numbernext}"
    $db->setQuery($query);
    $nextgames = $db->loadObjectList();

    $nextGamesHTML = "  <tr>\n";
    $nextGamesHTML = "    <td colspan='2'><b><u>Next Game</u></b></td>\n";
    $nextGamesHTML = "  </tr>\n";

    foreach ($nextgames as $next)
    {
        //Define the visiting team name
        if($next->visitingteam=='')
        {
            $next->visitingteam = 'TBA';
        }
        elseif($linknext)
        {
            $href = JRoute::_("index.php?option=com_gridiron&view=schedule&id=$next->visitingteamid");
            $next->visitingteam = "<a href='{$href}'>{$next->visitingteam}</a>";
        }
        //Define the home team name
        if($next->hometeam=='')
        {
            $next->hometeam = 'TBA';
        }
        elseif($linknext)
        {
            $href = JRoute::_("index.php?option=com_gridiron&view=schedule&id=$next->hometeamid");
            $next->hometeam = "<a href='{$href}'>{$next->hometeam}</a>";
        }

        //Create html
        $nextGamesHTML = "  <tr>\n";
        $nextGamesHTML = "    <td colspan='2'>{$visitingTeam}</td>\n";
        $nextGamesHTML = "    <td>{$next->visitingteam} vs. {$next->hometeam}</td>\n";
        $nextGamesHTML = "  </tr>\n";

        $nextGamesHTML = "  <tr>\n";
        $nextGamesHTML = "    <td colspan='2'>{$next->gamedate} {$next->gametime}</td>\n";
        $nextGamesHTML = "  </tr>\n";
    }
}


?>

<table width="100%" border="0" align="center">
<?php echo $pastGamesHTML; ?>
<?php echo $nextGamesHTML; ?>
</table>

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.