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

https://gist.github.com/LaocheXe/65be0a43db565f55e03194ed8852f05e

 

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
closed
in Plugins by (445 points) 15 35 49
closed by
You still have there while in while with the same! $sql1. Use retrieve or fix this. While after while works normally. But while in while cant use the same. Second one replaced last used query at first so after first cyclus it ends. I reported this at very first beginning of e107 v2, when I rushed to issue with content plugin. They said it was correct.

Using retrieve on $sql2 - I get
Fatal error: Uncaught Error: Call to undefined method db::retrive() in /usr/www/e107_plugins/rules/rules.php:119 Stack trace: #0 {main} thrown in /usr/www/e107_plugins/rules/rules.php on line 119

 

119: while(list($ladder_id, $ladder_name)=$sql2->retrive($getLadders))

db::retrive()  - retrieve() , you have mistypo there...

Thanks, sadly changing it to retrieve doesn't work - returns nothing.

If I leave them as fetch, I get somewhat desired effect, but only 1 game shows, If I can get all the games to show, it might work.
retrieve() has different parameters, you need to set that you want to return the array not first item.

I've edited the while for Game catagory - the code used:

$listGamesHere = "SELECT game_id, game_name, game_status FROM `#ewl_games` WHERE game_status = 1 ORDER BY game_name";

$gamesArray = array();

while($gameCat = $sql1->retrieve($listGamesHere)) {

$gamesArray[] = array( 'game_name' => $gameCat['game_name']);

print_r($gamesArray);

}

_____

Returns a ton of arrays that is only displaying the first game listed as Dota 2 - at the end of the page (long scroll)

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 130080768 bytes)

 

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) 17 48 57
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.
979 questions
1,376 answers
2,504 comments
2,496 users