Forums

Need help on connection code

Bullfn33 22 May, 2012
For Bob,

I am extremely grateful of your help with my Top 25 prediction form last year. You have saved me a lot of time setting those up each week. Now I am attempting to get the same set up on the new versions of CF and CC. I'm having one small issue that I cannot seem to tackle and since you wrote the code, I thought you might be able to help.

The part I'm having trouble with is the connection part that serves as a confirmation page for form results. I have simply used the form to display the results with some small changes. Below is part of the code from the form you wrote with what I've added in bold.

All of the variables populate correctly but the conditional statements that I added in bold do not display correctly in the form. The $label_away and $label_home variables always show up the same no matter what I've tried(four hrs worth😲). Either both label classes show up "checked" or both show up "unchecked" but they should always be the opposite.

<?php

function buildGame($game, $count, $teams)
{
global $mainframe;
if ( !count($game) ) {
return false;
}
$away = $teams[$game->away];
$home = $teams[$game->home];

$away_logo = strtolower($game->away);
$home_logo = strtolower($game->home);

if ( !$game->conf ) {
$game->conf = $game->number;
}
if ( $game->conf % 2 ) {
$tr_class = 'even';
} else {
$tr_class = 'odd';
}
$rowspan = '';
if ( $game->margin || ($game->number == $count && !$game->win ) ) {
$rowspan = 'rowspan="2"';
}
$tabindex_away = $game->conf * 2 - 1;
$tabindex_home = $game->conf * 2;

if ( $game->away == "{game_{$game->number}}" ) {
$label_away = 'checked';
} else {
$label_away = 'unchecked';
}
if ( $game->home == "{game_{$game->number}}" ) {
$label_home = 'checked';
} else {
$label_home = 'unchecked';
}


echo "<div id='game_div_{$game->number}' class='switch' >
<table>
<tbody>
<tr class='{$tr_class} game' id='game_{$game->number}' >
<td class='game-number' {$rowspan} >Game {$game->number}</td>
<td class='logo'>
<img src='http://nc2apredictions.com/images/logos/teams/{$away_logo}.gif' alt='{$away_logo}' />
</td>
<td class='team team_away'><span class='rank'>{$away->rank}</span>{$away->name}</td>
<td class='radios'>
<label class='{$label_away}'>
</label>

</td>
<td class='confidence' >
{game_{$game->number}_confidence}
</td>
<td class='radios'>
<label class='{$label_home}'>
</label>

</td>
<td class='team team_home'><span class='rank'>{$home->rank}</span>{$home->name}</td>
<td class='logo logo_home'>
<img src='http://nc2apredictions.com/images/logos/teams/{$home_logo}.gif' alt='{$home_logo}' />
</td>
<td class='right-end' {$rowspan} ></td>
</tr>";
if ( $game->number == $count ) {
$tabindex = $tabindex_home + 1;
echo " <tr class='{$tr_class} bonus'>
<td colspan='9' class='team-away-bonus-mg bonus'><span class='margin'>Margin of Victory
<input name='game_margin' type='text'
tabindex='{$tabindex}' size='2' maxlength='2' value='{$game->margin}' /></span></td>
</tr>
";
}
echo " </tbody>
</table>
</div>";
}
?>


The only thing I can think of for why it won't work is because the {game_{$game->number}} syntax from CC won't load the form result in an IF statement because it loads correctly if I place them in the table. I have a formhtml file loaded in the body section of the custom code box which I can attach if you need it. thanks again for all your help.

John
Max_admin 23 May, 2012
Hi,

Where do you call this function ? you should not use the curly brackets formula inside PHP, it will not run, try to use the PHP vars, $x_data for now, but $row in the new version.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Bullfn33 24 May, 2012
Attached is the entire file. My current best guess is from lines 183-194 using $x_data var but I'm not good with php. Somehow I need to get the user's data from field name "game_x" where x is the number of the game. Then compare that to game->home and game->away so that one label_class renders checked and the other unchecked in the table. I'm trying to place a background image depending on the label_class.
Max_admin 31 May, 2012
I think that something like this:

{game_{$game->number}}


should be in the newest version:

$row['game_'.$game->number]


But why do you have the code inside a function ? where should this code go ? in the header or body or ???
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Bullfn33 01 Jun, 2012
Hi Max,

Thanks for the updated version of CC today which works great now.

I tried replacing the code above with your suggestion but I get the same result for the label_classes which always come up "unchecked" in the front-end. The bold part in above post now looks like this:

    if ( $game->away == $row['game_'.$game->number] ) {
    $label_away = 'checked';
    } else {
    $label_away = 'unchecked';
    }
    if ( $game->home == $row['game_'.$game->number] ) {
    $label_home = 'checked';
    } else {
    $label_home = 'unchecked';
    }

I have the file loaded into the body box in CC. The reason why the code is in a function is because I have to update multiple forms every week with a different number of games. It allows me to simply plug in the games in the array (in attached file above) and the function renders the appropriate structure automatically for each game regardless of how many matches are typed into the array.

For some reason the codes I've tried to bring up the game_x field (x = # of the game) in that conditional statement is not displaying the users data for the field so it returns "unchecked" since neither returns an equal match. I have tried to use $row['game_'.$game->number], "{game_{$game->number}}" and others I can't recall right now.

I also tried $row['game_1'] to test and see if the Game 1 would return correctly and it did not. As a further test, I typed in the actual user's result from the game_1 field that is supposed to show up and that is the only time I got the correct label_class to display.

Based on these tests, will the users data not load because it is inside a function? Is there a way around this? thanks for your help.

John
Max_admin 03 Jun, 2012
Hi John,

I suggest that you take the code out of the function and test.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Bullfn33 03 Jun, 2012
The code works without the function but then it doesn't show all the games so I kind of need the function. I'll have to figure out something else. thanks

John
Max_admin 07 Jun, 2012
Try to get it working without the function, I still can't understand why do you need it ? what's the purpose of this function ? I may have some idea🙂
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Bullfn33 07 Jun, 2012
Hey Max,

Don't worry about it. I have found an alternative solution which is more efficient at what I was trying to accomplish using the DB record loader action through the form. Thanks very much for your help.

John
This topic is locked and no more replies can be posted.