e107help.org Q&A
0 like 0 dislike

Need help creating a front page - I'm working on rules page, and I'm having an issue with while, and foreach - the while statement would only show 1 entry, while foreach shows each entry weirdly. The code I've done previously was back when PHP5 was the main thing, using while(list) doesn't work anymore. I've run my SQL Queries in phpmyadmin and get the results, but can't get them to display correctly.

Here is the gist of the code



As shown below it List MechWarrior 4 Mercs, Then MechWarrior 4 Mercs with Dota 2 (Should only show Dota 2, then the Ladders for Dota 2 (which are none at the moment).

e107 version v2.3.0
in Plugins by (459 points) 16 35 50
closed by
Please look at examples how to use retrieve in developer docs. You have it totally wrong. Retrieve is already combination of select and fetch, so you have already needed result and foreach is used, not while.
Oops - Got it working some what.

Okay, Got it to list the games, and some what list the Ladders under each game - but the Ladders Repeat....

The Code:

if($gamesCats = $sql1->retrieve('ewl_games', 'game_id, game_name, game_status', 'game_status = 1 ORDER BY game_name', true))
        foreach($gamesCats as $gameCat)

            $gameSet = "<b>+ ".$gameCat['game_name']."</b><br />";

            $sqlLaddersCatagories = "SELECT ladder_id, ladder_name FROM `#ewl_ladders` WHERE game_id = ".$gameCat['game_id']."";
            $getLadders = $sql2->gen($sqlLaddersCatagories);
            while(list($ladder_id, $ladder_name)=$sql2->fetch($getLadders))
                $ladderList .= "&nbsp;<font class='catfont'>»</font><a href='rules.php?ruleid=".$ladder_id."'>".$ladder_name."</a><br />";

            $gameLadderSet .= $gameSet."".$ladderList."";


Take a peek --> http://ewl.defiantz.org/e107_plugins/rules/rules.php

before first ladder of game (before while), you need to set $ladderList = '';

otherwise, you use values from former games.

1 Answer

0 like 0 dislike
Best answer
I think you cant have fetch() inside while with other fetch(). If this is your case, replace it with retrieve or you need to use $sql1, $sql2...
by (2.0k points) 18 48 58
selected by
I've tried that, still comes out the same - which is weird.
Still having issues, I've updated the gist with the updated code, I got it showing only 1 instead of the full list it should display.


The webpage: http://ewl.defiantz.org/e107_plugins/rules/rules.php

What I'm trying to re-create: http://league.clancoyote.com/league/rules.php
Welcome to e107 Q&A, where you can ask questions and receive answers from other members of the e107 community.
988 questions
1,384 answers
2,511 users